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

How do I jump between diff hunks when comparing files with Vim's built-in diff mode?

Answer

]c and [c

Explanation

When files are open in Vim's built-in diff mode — whether via vimdiff, :diffsplit, or :diffthis — the ]c and [c motions let you jump precisely between changed hunks. Instead of scrolling through large files looking for highlighted changes, you can leap directly from one change to the next with a single keystroke.

How it works

  • ]c jumps forward to the next changed hunk (change) below the cursor
  • [c jumps backward to the previous changed hunk above the cursor
  • Both motions work in any window of a diff session — the jumps are relative to the cursor position, not the window
  • A count prefix like 3]c skips ahead three hunks at once
  • If no more hunks exist in that direction, Vim reports "No more changes"

Example

With two files open side by side via vimdiff file1 file2:

--- file1 ---        --- file2 ---
line 1               line 1
[change A]           [change A']
line 3               line 3
line 4               line 4
[change B]           [change B']

With the cursor at the top of the file, ]c jumps to change A, another ]c jumps to change B. Pressing [c from change B jumps back to change A.

Tips

  • After landing on a hunk, use dp (diff put) or do (diff obtain) to apply or discard the change
  • Use :diffupdate if the highlights become stale after editing
  • These motions also work in three-way merge sessions (e.g. vimdiff base local remote)

Next

How do I combine two recorded macros into one without re-recording them from scratch?