Vim field guide · dot-files

vim-gitgutter

Shows which lines you have added, modified, or removed since the last git commit, directly in the sign column.

▎ added line
▎ modified line
▁ removed below this line

Working with hunks

KeyAction
<leader>hpPreview hunk diff in a floating window
<leader>hsStage hunk (without leaving Vim)
<leader>huUndo hunk (revert to HEAD)

Staging individual hunks is useful when a file has multiple unrelated changes and you want to commit them separately.

Viewing commit history

KeyAction
<leader>gcBrowse per-file commit history with diff preview (:BCommits via fzf)
<leader>gsSearch git log for the exact line or visual selection under cursor

Text objects

Gitgutter registers ic and ac as hunk text objects:

KeyAction
vicSelect inside hunk (visual)
vacSelect around hunk (visual)
dicDelete inside hunk
yicYank inside hunk

Commands

CommandAction
:GitGutterToggleToggle signs on/off
:GitGutterLineHighlightsToggleToggle full-line background highlights
:GitGutterFoldFold all unchanged lines (focus on the diff)
:GitGutterQuickFixLoad all hunks into the quickfix list

Config (from .vimrc)

set updatetime=250        " refresh signs within 250ms of stopping edits
set signcolumn=yes        " always show the sign column (prevents layout shift)
let g:gitgutter_sign_added    = '▎'
let g:gitgutter_sign_modified = '▎'
let g:gitgutter_sign_removed  = '▁'