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

How do I see Git diff markers in the sign column?

Answer

vim-gitgutter plugin

Explanation

vim-gitgutter shows git diff markers in the sign column next to line numbers. Added lines show +, modified lines show ~, and deleted lines show -.

How it works

  • Install the plugin and signs appear automatically
  • + in the gutter marks added lines
  • ~ marks modified lines
  • - marks deleted lines
  • Updates asynchronously as you edit

Example

After modifying a git-tracked file, the gutter shows:

    1  unchanged line
 +  2  newly added line
 ~  3  modified line
    4  unchanged line
 -  5  (line was deleted after this)

Tips

  • Install: Plug 'airblade/vim-gitgutter'
  • ]c / [c jump between hunks
  • :GitGutterPreviewHunk previews the change at cursor
  • :GitGutterStageHunk stages the hunk under cursor
  • :GitGutterUndoHunk reverts the hunk
  • let g:gitgutter_enabled = 0 disables by default

Next

How do you yank a single word into a named register?