vimtricks.wiki Concise Vim tricks, one at a time.

How do I make two windows scroll together in sync?

Answer

:set scrollbind

Explanation

The scrollbind option locks the scrolling of two or more windows together so they scroll in unison. This is ideal for comparing files side by side.

How it works

  • Open two windows (:vsplit or :split)
  • Run :set scrollbind in each window you want to synchronize
  • Scrolling in any bound window scrolls all bound windows together

Example

:vsplit other_file.txt
:set scrollbind
:wincmd w
:set scrollbind

Now scrolling in either window scrolls both.

Tips

  • :set noscrollbind disables it
  • :set cursorbind also synchronizes cursor position
  • diffthis automatically enables scroll binding
  • :syncbind re-synchronizes the scroll positions

Next

How do you yank a single word into a named register?