Skip to content

Commit 7b33898

Browse files
committed
Merge branch 'master' of github.com:airblade/vim-gitgutter
2 parents 76b46ba + dbfbbb4 commit 7b33898

2 files changed

Lines changed: 69 additions & 26 deletions

File tree

README.mkd

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ cd ~/.vim/bundle
2525
git clone git://github.com/airblade/vim-gitgutter.git
2626
```
2727

28+
Or for [Vundle](https://github.com/gmarik/vundle) users:
29+
30+
Add `Bundle 'airblade/vim-gitgutter'` to your `~/.vimrc` and then:
31+
32+
* either within Vim: `:BundleInstall`
33+
* or in your shell: `vim +BundleInstall +qall`
34+
2835

2936
### Usage
3037

@@ -34,15 +41,15 @@ If you want vim-gitgutter off by default, add `let g:gitgutter_enabled = 0` to y
3441

3542
You can explicitly turn vim-gitgutter off and on:
3643

37-
* turn off with `:DisableGitGutter`
38-
* turn on with `:EnableGitGutter`
39-
* toggle with `:ToggleGitGutter`.
44+
* turn off with `:GitGutterDisable`
45+
* turn on with `:GitGutterEnable`
46+
* toggle with `:GitGutterToggle`.
4047

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

43-
* turn on with `:EnableGitGutterLineHighlights`
44-
* turn off with `:DisableGitGutterLineHighlights`
45-
* toggle with `:ToggleGitGutterLineHighlights`.
50+
* turn on with `:GitGutterLineHighlightsEnable`
51+
* turn off with `:GitGutterLineHighlightsDisable`
52+
* toggle with `:GitGutterLineHighlightsToggle`.
4653

4754
Furthermore you can jump between hunks:
4855

@@ -71,9 +78,27 @@ Vim only allows one sign per line. Before adding a sign to a line, vim-gitgutte
7178

7279
### Alternatives
7380

74-
I'm not aware of any other Vim plugins which (only) show git diffs in the gutter. However these may be of interest:
81+
Related:
82+
83+
* [textobj-gitgutter][togg] (lets you treat diff hunks as text objects)
84+
85+
Vim alternatives:
86+
87+
* [git-gutter-vim][ggv]
88+
* [vim-git-inline-diff][vgid]
89+
* [quickfixsigns_vim][qf] (a superset of this functionality)
90+
* [iwilldiffer][iwd]
91+
* [svndiff][svndiff]
92+
* [sign-diff][signdiff]
93+
* [changesPlugin][changes]
94+
95+
Other editors:
96+
97+
* [Git Gutter][st2gg] for Sublime Text 2
98+
* [git-gutter.el][gge] for Emacs
99+
100+
Also, this may be of interest:
75101

76-
* [quickfixsigns_vim][qf] has a large superset of this functionality.
77102
* [fugitive.vim][fugitive] is a full-on Git wrapper. It doesn't show git diffs in the gutter (ha!) but it does a bazillion other git things.
78103

79104

@@ -99,4 +124,11 @@ Copyright Andrew Stewart, AirBlade Software Ltd. Released under the MIT licence
99124
[siv1]: https://peepcode.com/products/smash-into-vim-i
100125
[siv2]: https://peepcode.com/products/smash-into-vim-ii
101126
[portfolio]: http://airbladesoftware.com/portfolio#vim
102-
127+
[vgid]: https://github.com/luxflux/vim-git-inline-diff
128+
[gge]: https://github.com/syohex/emacs-git-gutter
129+
[iwd]: https://bitbucket.org/sirpengi/iwilldiffer
130+
[svndiff]: http://www.vim.org/scripts/script.php?script_id=1881
131+
[signdiff]: http://www.vim.org/scripts/script.php?script_id=2712
132+
[changes]: http://www.vim.org/scripts/script.php?script_id=3052
133+
[ggv]: https://github.com/akiomik/git-gutter-vim
134+
[togg]:https://github.com/gilligan/textobj-gitgutter

plugin/gitgutter.vim

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,29 @@ function! s:directory_of_current_file()
8282
return shellescape(expand("%:p:h"))
8383
endfunction
8484

85+
function! s:discard_stdout_and_stderr()
86+
if !exists('s:discard')
87+
if &shellredir ==? '>%s 2>&1'
88+
let s:discard = ' > /dev/null 2>&1'
89+
else
90+
let s:discard = ' >& /dev/null'
91+
endif
92+
endif
93+
return s:discard
94+
endfunction
95+
8596
function! s:command_in_directory_of_current_file(cmd)
8697
return 'cd ' . s:directory_of_current_file() . ' && ' . a:cmd
8798
endfunction
8899

89100
function! s:is_in_a_git_repo()
90-
let cmd = 'git rev-parse > /dev/null 2>&1'
101+
let cmd = 'git rev-parse' . s:discard_stdout_and_stderr()
91102
call system(s:command_in_directory_of_current_file(cmd))
92103
return !v:shell_error
93104
endfunction
94105

95106
function! s:is_tracked_by_git()
96-
let cmd = 'git ls-files --error-unmatch > /dev/null 2>&1 ' . shellescape(s:current_file())
107+
let cmd = 'git ls-files --error-unmatch' . s:discard_stdout_and_stderr() . ' ' . shellescape(s:current_file())
97108
call system(s:command_in_directory_of_current_file(cmd))
98109
return !v:shell_error
99110
endfunction
@@ -323,41 +334,41 @@ function! GitGutter()
323334
endfunction
324335
command GitGutter call GitGutter()
325336

326-
function! DisableGitGutter()
337+
function! GitGutterDisable()
327338
let g:gitgutter_enabled = 0
328339
call s:clear_signs(s:current_file())
329340
endfunction
330-
command DisableGitGutter call DisableGitGutter()
341+
command GitGutterDisable call GitGutterDisable()
331342

332-
function! EnableGitGutter()
343+
function! GitGutterEnable()
333344
let g:gitgutter_enabled = 1
334345
call GitGutter()
335346
endfunction
336-
command EnableGitGutter call EnableGitGutter()
347+
command GitGutterEnable call GitGutterEnable()
337348

338-
function! ToggleGitGutter()
349+
function! GitGutterToggle()
339350
if g:gitgutter_enabled
340-
call DisableGitGutter()
351+
call GitGutterDisable()
341352
else
342-
call EnableGitGutter()
353+
call GitGutterEnable()
343354
endif
344355
endfunction
345-
command ToggleGitGutter call ToggleGitGutter()
356+
command GitGutterToggle call GitGutterToggle()
346357

347-
function! DisableGitGutterLineHighlights()
358+
function! GitGutterLineHighlightsDisable()
348359
call s:update_line_highlights(0)
349360
endfunction
350-
command DisableGitGutterLineHighlights call DisableGitGutterLineHighlights()
361+
command GitGutterLineHighlightsDisable call GitGutterLineHighlightsDisable()
351362

352-
function! EnableGitGutterLineHighlights()
363+
function! GitGutterLineHighlightsEnable()
353364
call s:update_line_highlights(1)
354365
endfunction
355-
command EnableGitGutterLineHighlights call EnableGitGutterLineHighlights()
366+
command GitGutterLineHighlightsEnable call GitGutterLineHighlightsEnable()
356367

357-
function! ToggleGitGutterLineHighlights()
368+
function! GitGutterLineHighlightsToggle()
358369
call s:update_line_highlights(s:highlight_lines ? 0 : 1)
359370
endfunction
360-
command ToggleGitGutterLineHighlights call ToggleGitGutterLineHighlights()
371+
command GitGutterLineHighlightsToggle call GitGutterLineHighlightsToggle()
361372

362373
function! GitGutterNextHunk()
363374
if s:is_active()
@@ -408,7 +419,7 @@ endfunction
408419

409420
augroup gitgutter
410421
autocmd!
411-
autocmd BufReadPost,BufWritePost,FileReadPost,FileWritePost * call GitGutter()
422+
autocmd BufReadPost,BufWritePost,FileReadPost,FileWritePost,FocusGained * call GitGutter()
412423
augroup END
413424

414425
" }}}

0 commit comments

Comments
 (0)