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
:windoexecutes a command in each window in the current tabsetlocalkeeps the change window-local instead of globalscrollbindmakes windows follow each other when you scrollcursorbindkeeps 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 nocursorbindwhen you are done comparing - Use
zt,zz, orzbin one window to quickly re-center all bound windows - Apply this after opening all comparison windows so every target split is included