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

How do I keep multiple split windows scrolling and cursoring in sync?

Answer

:windo setlocal scrollbind cursorbind

Explanation

When reviewing related files side by side, alignment drifts quickly if each window scrolls independently. This command applies both scrollbind and cursorbind to every open window so vertical movement and cursor position stay synchronized. It is useful for code reviews, config diffs, and tracking the same logical section across parallel implementations.

How it works

:windo setlocal scrollbind cursorbind
  • :windo executes a command in each window in the current tab
  • setlocal keeps the change window-local instead of global
  • scrollbind makes windows follow each other when you scroll
  • cursorbind keeps cursor line/column movements synchronized too

Example

Before:

left split: scrolling at line 120
right split: still at line 80

After applying the command and moving in either split:

both splits track the same relative position and cursor row

Tips

  • Turn it off with :windo setlocal noscrollbind nocursorbind when you are done comparing
  • Use zt, zz, or zb in one window to quickly re-center all bound windows
  • Apply this after opening all comparison windows so every target split is included

Next

How do I regenerate help tags for every installed plugin in one command?