2013-03-08 12:48:48 +01:00
2013-03-07 15:08:55 +01:00
2013-03-07 15:08:55 +01:00
2013-03-08 11:45:13 +01:00
2013-02-20 10:53:23 +01:00

Vim Git Gutter

A Vim plugin which shows a git diff in the 'gutter' (sign column). It shows whether each line has been added, modified, and where lines have been removed.

This is a port of the Git Gutter plugin for Sublime Text 2.

Screenshot

screenshot

In the screenshot above you can see:

  • Line 15 has been modified.
  • Lines 21-24 are new.
  • A line or lines were removed between lines 25 and 26.

Installation

If you don't have a preferred installation method, I recommend installing pathogen.vim, and then simply copy and paste:

cd ~/.vim/bundle
git clone git://github.com/airblade/vim-gitgutter.git

Or for Vundle users:

Add Bundle 'airblade/vim-gitgutter' to your ~/.vimrc and then:

  • either within Vim: :BundleInstall
  • or in your shell: vim +BundleInstall +qall

Usage

You don't have to do anything: it just works.

If you want vim-gitgutter off by default, add let g:gitgutter_enabled = 0 to your ~/.vimrc.

You can explicitly turn vim-gitgutter off and on:

  • turn off with :GitGutterDisable
  • turn on with :GitGutterEnable
  • toggle with :GitGutterToggle.

And you can turn line highlighting on and off (defaults to off):

  • turn on with :GitGutterLineHighlightsEnable
  • turn off with :GitGutterLineHighlightsDisable
  • toggle with :GitGutterLineHighlightsToggle.

Furthermore you can jump between hunks:

  • jump to next hunk: :GitGutterNextHunk
  • jump to previous hunk: :GitGutterPrevHunk.

You may want to add mappings for these if you use them often.

If you want to define your own highlights, you can turn off vim-gitgutter's with let g:gitgutter_highlights = 0 in your ~/.vimrc.

Customisation

  • The sign column's colours
  • The signs' colours
  • The signs' symbols
  • Line highlights
  • Whether or not vim-gitgutter is on initially (defaults to on)
  • Whether or not line highlighting is on initially (defaults to off)

Please note that vim-gitgutter won't override any colours or highlights you've set in your colorscheme.

Sign column

The background colour of the sign column is controlled by the SignColumn highlight group. This will be either set in your colour scheme or Vim's default.

To find out where it's set, and to what it's set, use :verbose highlight SignColumn.

If your SignColumn is not set (:highlight SignColumn gives you SignColumn xxx cleared), vim-gitgutter will set it to the same as your line number column (i.e. the LineNr highlight group).

To change your sign column's appearance, update your colour scheme or ~/.vimrc like this:

  • For the same appearance as your line number column: highlight clear SignColumn
  • For a specific appearance on terminal Vim: highlight SignColumn ctermbg=whatever
  • For a specific appearance on gVim/MacVim: highlight SignColumn guibg=whatever

Signs' colours

To customise these, put this in your colorscheme or ~/.vimrc:

FAQ

The colours in the sign column are weird.

Please see the section above on customising the sign column.

What happens if I also use another plugin which uses signs (e.g. Syntastic)?

Vim only allows one sign per line. Before adding a sign to a line, vim-gitgutter checks whether a sign has already been added by somebody else. If so it doesn't do anything. In other words vim-gitgutter won't overwrite another plugin's signs. It also won't remove another plugin's signs.

Alternatives

Related:

Vim alternatives:

Other editors:

Also, this may be of interest:

  • fugitive.vim is a full-on Git wrapper. It doesn't show git diffs in the gutter (ha!) but it does a bazillion other git things.

Shameless Plug

If this plugin has helped you, or you'd like to learn more about Vim, why not check out these two screencasts I wrote for PeepCode:

You can read reviews at PeepCode and also on my portfolio.

Intellectual Property

Copyright Andrew Stewart, AirBlade Software Ltd. Released under the MIT licence.

Description
A Vim plugin which shows git diff markers in the sign column and stages/previews/undoes hunks and partial hunks.
Readme 2 MiB
Languages
Vim Script 99.6%
Shell 0.4%