6

I have a single buffer open across multiple vertically split windows and all the windows have scrollbind set. However, before setting scrollbind, I had to scroll down in second window in order to make sure that text in second window starts where it ends in first window. In addition, I had to scroll down the text in third window in order to make sure that it starts where it ends in second window. When this was done I set the scrollbind. Is there an easier way? Scrolling in all the vertically split windows is tedious.

// EDIT: I added a screenshot. As seen below, I have same file(1000_line_file.txt) open in three windows and I have scrolled the second and third window in a way that first line in second window is line nr 88, last line in second window is line nr 174 and first line in third windows is line nr 175. At this point I want to execute :windo set scrollbind to lock the scrolling. However, this scrolling process in vertically split windows is tedious.

enter image description here

3

If you need to make a couple of splits synced with an increasing offset, the routine would be:

  1. Split the window vertically C-w v
  2. Move to the next window C-w w
  3. Scroll down one screen C-f (add C-e as needed)
  4. Repeat steps 1 - 3

Now as all splits are open and you are on the last one, you need to bind them:

  1. :set scrollbind
  2. Move to the previous window C-w W
  3. :set scrollbind
  4. Repeat steps 6 and 7

Record the macro once and that's it. You can use :windo set scrollbind instead, but this way it will work even if you have other windows open. Here how it looks like in a register:

^Wv^Ww^F^E^E^Wv^Ww^F^E^E:set scrollbind^@^WW:set scrollbind^@^WW:set scrollbind^@

enter image description here

Also worth mentioning. Commands replayed by macro are not registered in the history, so : C-p Return or @: will execute the most recent command before the replay.

1

You might be interested in Dr. Chips MPage plugin, which does exactly this. From the documentation:

MPage shows a file in multiple windows, with each sequential window showing sequential lines of text, rather like a book.

Usage:

:MPage [splits]
:[splits]MPage
0

:syncbind

This will Force all 'scrollbind' windows to have the same relative offset.

Just be sure you aren't using scrollbar of non-focused windows as it only works with focused window (and, of course, keyboard scrolling works).

Edit: I posted the above before the question had extra details added. However syncbind could still help with automating the syncing of multiple windows, each one page ahead of the preceding...

Let's say you open 2 splits (for 3 total windows) then do some unrelated work. Now each window is on a different line. But as long as one window is on the line that you want to be relative to this would set you up:

  1. :windo set scrollbind
  2. :syncbind (each window is now synced to the same line)
  3. :windo set noscrollbind (temporarily unbind)
  4. In second window: CtrlF
  5. In third window: CtrlF, CtrlF
  6. :windo set scrollbind

Obviously you'd want to put this in a script (or a macro per Sergey's answer).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.