170

I'm trying to edit some assembly code which tends to be formatted in long but thin listings. I'd like to be able to use some of the acres of horizontal space I have and see more code on-screen at one time. Is there a method for getting Emacs (or indeed another editor) to show me multiple columns all pointing to the same buffer?

C-x 3 (emacs) and :vsplit (vim) are great for multiple separate views into the code, but I'd like it to flow from one column to the other (like text in a newspaper).

user119857
  • 1,771
  • 3
  • 12
  • 9
  • 1
    C-x 3 and :vsplit are great for multiple separate views into the code, but I'd like it to flow from one column to the other (like text in a newspaper) – user119857 Jun 09 '09 at 14:24
  • 1
    Thanks! I fell in love with 4-6 column code viewing that I tried formatting all my code to 30-40 chars, and I'm loving the result extremely — by making all lines short, not just the naturally short ones, a lot less space is wasted, and all my screen space is used to display text; also, code blocks become more 2-dimensional, easing visual comprehension and structural oversight. – Erik Kaplun Jan 08 '16 at 01:38

7 Answers7

256

See follow-mode. Excerpt:

Follow mode is a minor mode that makes two windows, both showing the same buffer, scroll as a single tall “virtual window.” To use Follow mode, go to a frame with just one window, split it into two side-by-side windows using C-x 3, and then type M-x follow-mode. From then on, you can edit the buffer in either of the two windows, or scroll either one; the other window follows it. In Follow mode, if you move point outside the portion visible in one window and into the portion visible in the other window, that selects the other window—again, treating the two as if they were parts of one large window.
huaiyuan
  • 26,129
  • 5
  • 57
  • 63
  • 3
    Can I use this with more than two windows? Can I have four windows using this? – Yktula Apr 14 '10 at 23:47
  • I wonder if it is possible to edit two columns of the same source in an individual way, not splitted in two windows. This is not the best example but imagine that I have one column for the script code and the other for comments then if I am in the second column I want to press "enter" and continue in the next line but in the second column. Is this possible with Emacs or other text editor? – sw. Jan 02 '12 at 15:13
  • 1
    It's very useful to edit long long function or method. i always find this mode and open two buffer and do this by myself, thanks huaiyuan – Yuan He Aug 27 '13 at 16:04
18

I use this function to invoke follow-mode, although it would need customization for a different screen size:

;;; I want a key to open the current buffer all over the screen.
(defun all-over-the-screen ()
  (interactive)
  (delete-other-windows)
  (split-window-horizontally)
  (split-window-horizontally)
  (balance-windows)
  (follow-mode t))
  • Plus 1 for pointing out (balance-windows) alone! I guess though you could make it split a parametric number of times and make the function interactive. Also, setting `scroll-margin` to `0` will make sense in `follow-mode`. – Erik Kaplun Jan 08 '16 at 03:13
17

The "Multipager" plugin for Vim can do this with VIM splits for people who want to get this behavior in Vim.

Get it from Dr. Chip's page: http://mysite.verizon.net/astronaut/vim/index.html#MPAGE

Docs: http://mysite.verizon.net/astronaut/vim/doc/mpage.txt.html

bheeshmar
  • 3,125
  • 1
  • 19
  • 18
2

Vim can do this using :vsplit - and you can have the same buffer open in multiple "windows" (which are actually sections within a single "window").

Documentation here

brettkelly
  • 27,655
  • 8
  • 56
  • 72
  • 3
    emacs can do that too, as mentioned in the question, but that's not what is being asked. – justinhj Jun 15 '09 at 20:52
  • 1
    Combine that with `:scrollbind`, and you are there. – bastibe Jul 24 '11 at 09:10
  • @Kragen -- The method to do this is: 1. split the window vertically, so single buffer is visible in two windows 2. scroll in the second window so that first line in second window comes after last line in first window, 3. issue command `:set scrollbind` in each of the windows. Now the windows will scroll together as desired. (Note: scrollopt must contain 'ver' option.) – Herbert Sitz Sep 23 '11 at 18:35
  • Hmm, that does sort of work. Cool! Thanks! Someone should write a vim script to do this automatically. – Kragen Javier Sitaker Oct 07 '11 at 03:10
  • :scrollbind and :cursorbind doesn't do the follow-mode job! If you see the emacs follow-mode then you can realize what is the functionality he's talking about. follow-mode is a little smarter, you are watching the first section of a buffer in one window and see the rest of that file in another window. – SdSaati Aug 16 '20 at 13:25
-1

A quick look at the emacs wiki doesn't show a mode like you describe. However, it shouldn't be too hard to write one... You just need to split the window with C-x 3 and move the text in the other window down, and whenever you move the text, do the same to the other window...

Problems may occur when you get to the bottom of the buffer, do you want the cursor to immediately go to the other window at the top?

Hmm, maybe its not that easy. But it should still be doable...

Brian Postow
  • 11,709
  • 17
  • 81
  • 125
-5

this is the default behaviour of emacs when splitting the window (C-x 3 for vertical split) you get two columns which both have the current buffer open

second
  • 28,029
  • 7
  • 75
  • 76
  • 1
    But in that case, it's not in follow-mode. Follow-mode will ensure that each buffer will be positioned at the "next page" so you can read through the buffer by moving your eyes rather than moving the point. – jrockway Jul 23 '11 at 21:23
-7

Use vertical-split with C-x 3. This will split the current buffer into two columns that you can switch between with C-x o.

Nathaniel Flath
  • 15,477
  • 19
  • 69
  • 94