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 (
:vsplitor:split) - Run
:set scrollbindin 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 noscrollbinddisables it:set cursorbindalso synchronizes cursor positiondiffthisautomatically enables scroll binding:syncbindre-synchronizes the scroll positions