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

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

  • cursorbind synchronizes the cursor column across bound windows, so moving left/right in one window moves the cursor in the other
  • scrollbind synchronizes 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 cursorbind to enable it in all open windows at once
  • Disable with :windo set nocursorbind nosyncbind
  • cursorbind without scrollbind syncs columns but not rows — useful for comparing two versions of the same very long single line
  • For diff mode, :windo diffthis is usually better; cursorbind shines for non-diff columnar comparison

Next

How do I prepend a value to the front of a comma-separated Vim option like path or runtimepath?