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

How do I jump between changed lines in a Git-tracked file in Vim?

Answer

]c / [c

Explanation

The vim-gitgutter plugin shows Git diff markers in the sign column and provides ]c and [c mappings to jump between changed hunks — groups of added, modified, or deleted lines compared to the Git index. This lets you quickly navigate to every change you have made in a file without scrolling or searching.

How it works

With vim-gitgutter installed and a Git-tracked file open:

  • ]c jumps to the next hunk (changed region)
  • [c jumps to the previous hunk

The sign column displays markers next to each changed line:

Sign Meaning
+ Added line
~ Modified line
- Deleted line (shown on the line above/below)

Staging and undoing individual hunks

Once you navigate to a hunk, you can act on it directly:

<Leader>hs    " stage the hunk (git add -p equivalent)
<Leader>hu    " undo the hunk (revert to the index version)
<Leader>hp    " preview the hunk diff in a floating window

This gives you git add -p granularity without leaving Vim — stage only the changes you want, and undo the rest.

Hunk text object

Gitgutter provides the ic and ac text objects for selecting the current hunk:

vic     " visually select the current hunk (inner)
vac     " visually select the current hunk (around, includes trailing newline)
dic     " delete the current hunk
yic     " yank the current hunk

This lets you combine hunk navigation with any Vim operator.

Previewing changes

Press <Leader>hp on a hunk to open a preview window showing exactly what changed. For modified lines, you see a unified diff. For deleted lines, you see the removed content. Close the preview with :pclose or <C-w>z.

Folding unchanged lines

Run :GitGutterFold to fold all unchanged lines in the file, leaving only the modified hunks visible. This is incredibly useful during code review to focus on just the changes. Run zR to unfold everything again.

Useful configuration

Add these settings to your vimrc for a better experience:

set updatetime=100              " faster sign updates (default is 4000ms)
let g:gitgutter_map_keys = 0    " disable default mappings, set your own
nmap ]c <Plug>(GitGutterNextHunk)
nmap [c <Plug>(GitGutterPrevHunk)
nmap <Leader>hs <Plug>(GitGutterStageHunk)
nmap <Leader>hu <Plug>(GitGutterUndoHunk)
nmap <Leader>hp <Plug>(GitGutterPreviewHunk)

Tips

  • Use counts with hunk navigation: 3]c jumps forward 3 hunks
  • Combine ]c with <Leader>hs for a rapid stage workflow: jump to hunk, review, stage, repeat
  • For Neovim users, gitsigns.nvim provides equivalent functionality with Lua configuration and virtual text support
  • Gitgutter works alongside vim-fugitive — use gitgutter for line-level changes and fugitive for commit-level operations
  • Run :GitGutterToggle to temporarily disable the signs if they are distracting during editing

Next

How do I edit multiple lines at once using multiple cursors in Vim?