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_fileor:split other_file) - Run
:windo set scrollbindto 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 typingnoscrollbind - If the windows get out of sync (e.g., after jumping to a search result in one window), run
:syncbindto re-synchronize them - Set
scrolloptto control binding behavior::set scrollopt=ver,hor,jumpenables vertical sync, horizontal sync, and jump synchronization - For a full diff experience, use
:windo diffthisinstead — 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
:diffthisin each - Disable the diff with
:windo diffoffwhich 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 cursorbindto also synchronize the cursor position (line and column) across bound windows