How do I keep the cursor column synchronized across two split windows while comparing files?
Answer
:set cursorbind
Explanation
:set cursorbind (or :setlocal cursorbind) locks the cursor's column position so it moves in sync across all windows that have cursorbind enabled. When combined with scrollbind, both the scroll position and the cursor column stay aligned — useful when comparing structured data, CSV files, or columns of aligned text side by side.
How it works
cursorbindsynchronizes the cursor column across bound windows, so moving left/right in one window moves the cursor in the otherscrollbindsynchronizes the scroll offset (which lines are visible)- Together they give you locked-viewport, locked-cursor comparison between two buffers
- Run
:set cursorbind(or:windo set cursorbind) in each window to enable binding
Example
" Open two files side by side
:vsplit other-file.txt
" Bind both windows for cursor and scroll synchronization
:windo set cursorbind scrollbind
" Now moving the cursor in either window moves both
Tips
- Use
:windo set cursorbindto enable it in all open windows at once - Disable with
:windo set nocursorbind nosyncbind cursorbindwithoutscrollbindsyncs columns but not rows — useful for comparing two versions of the same very long single line- For diff mode,
:windo diffthisis usually better;cursorbindshines for non-diff columnar comparison