16

I want to open up two different parts of a document in horizontal splits (using :sp) and scroll both of them left and right together. For vertical scrolling, you would use scrollbind. However, I'm not sure what to use for horizontal scrolling.

I know the capability must be available because when I use vimdiff, it scrolls horizontally in both documents at the same time.

19

To scroll two windows together in vim, need to run :set scrollbind in each of them. As you noted, by default, this only binds vertical scrolling. In the docs for scrollbind, it mentions:

The behavior of 'scrollbind' can be modified by the 'scrollopt' option.

:help scrollopt reveals that you want to say :set scrollopt+=hor to enable horizontal scrolling.

If you just want horizontal scrolling (i.e. disable vertical scrolling), then you will also want to say :set scollopt-=ver or explicitly set scrollopt via set scrollopt=hor or :set scrollopt=hor,jump.

  • Cannot fully decouple scrolling. After having :set scrollopt= (equal nothing) still move commands like 'm (jump to mark "m") or gg are performed on both my two windows. It's ubuntu gvim after doing a :vertical split with no file specified – Juan Lanus May 27 '16 at 18:09
  • Apparently I solved the issue mentioned in the previous comment by setting :set nocursorbind in addition to :set scrollopt= (nothing) – Juan Lanus May 27 '16 at 18:29
  • Not fully solved. Another option was left, :set nodiff. My vim was thinking that I was diffing two views of the same file. The nodiff option removed the all-dashes lines that vimdiff uses to sync both sides. – Juan Lanus May 27 '16 at 21:18

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.