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

How do I scroll two split windows in sync so they move together?

Answer

:windo set scrollbind

Explanation

The scrollbind option locks two or more windows together so that scrolling in one window automatically scrolls the others by the same amount. This is invaluable for comparing files side by side, reviewing diffs manually, or reading a translation alongside its original.

How it works

  • Open two or more files in splits (:vsplit other_file or :split other_file)
  • Run :windo set scrollbind to enable scroll binding in every visible window
  • Now scrolling in any window scrolls all bound windows simultaneously
  • To disable, run :windo set noscrollbind

:windo executes the command in each window in turn, so every window gets scrollbind enabled at once. You can also set it individually in specific windows by navigating to each one and running :set scrollbind.

Example

Compare two versions of a config file side by side:

:vsplit config_old.yaml
:windo set scrollbind

Now as you scroll through config.yaml on the left, config_old.yaml on the right scrolls in lockstep. Differences between the two files are easy to spot visually.

To align both windows at a specific point, navigate each window to the corresponding line and run :syncbind — this resets the scroll offset so both windows are aligned from that point forward.

Tips

  • Use :set scrollbind! to toggle scrollbind on and off in the current window without typing noscrollbind
  • If the windows get out of sync (e.g., after jumping to a search result in one window), run :syncbind to re-synchronize them
  • Set scrollopt to control binding behavior: :set scrollopt=ver,hor,jump enables vertical sync, horizontal sync, and jump synchronization
  • For a full diff experience, use :windo diffthis instead — it enables scrollbind automatically along with inline change highlighting and folding of identical sections
  • To diff only two specific windows (not all visible ones), navigate to each window individually and run :diffthis in each
  • Disable the diff with :windo diffoff which also turns off scrollbind
  • Scrollbind works with any number of windows — you can bind three or more windows together for multi-way comparisons
  • Combine with set cursorbind to also synchronize the cursor position (line and column) across bound windows

Next

How do I edit multiple lines at once using multiple cursors in Vim?