Allow user to turn GitGutter off and on.

This commit is contained in:
Andy Stewart
2013-02-26 09:35:04 +01:00
parent e989037f84
commit 0c16f257d6
2 changed files with 22 additions and 1 deletions

View File

@@ -26,6 +26,13 @@ git clone git://github.com/airblade/vim-gitgutter.git
``` ```
### Usage
You don't have to do anything: it just works.
You can turn vim-gitgutter off with `:call DisableGitGutter()` and on again with `:call EnableGitGutter()`. If you do this often I suggest adding mappings for these.
### FAQ ### FAQ
> The colours in the sign column are weird. > The colours in the sign column are weird.

View File

@@ -5,6 +5,8 @@ let g:loaded_gitgutter = 1
" Initialisation {{{ " Initialisation {{{
let s:gitgutter_enabled = 1
function! s:init() function! s:init()
if !exists('g:gitgutter_initialised') if !exists('g:gitgutter_initialised')
call s:define_highlights() call s:define_highlights()
@@ -40,6 +42,10 @@ endfunction
" Utility {{{ " Utility {{{
function! s:is_gitgutter_enabled()
return s:gitgutter_enabled
endfunction
function! s:current_file() function! s:current_file()
return expand("%:p") return expand("%:p")
endfunction endfunction
@@ -215,7 +221,7 @@ endfunction
" Public interface {{{ " Public interface {{{
function! GitGutter() function! GitGutter()
if s:exists_current_file() && s:is_in_a_git_repo() && s:is_tracked_by_git() if s:is_gitgutter_enabled() && s:exists_current_file() && s:is_in_a_git_repo() && s:is_tracked_by_git()
call s:init() call s:init()
let diff = s:run_diff() let diff = s:run_diff()
let hunks = s:parse_diff(diff) let hunks = s:parse_diff(diff)
@@ -227,6 +233,14 @@ function! GitGutter()
endif endif
endfunction endfunction
function! DisableGitGutter()
let s:gitgutter_enabled = 0
endfunction
function! EnableGitGutter()
let s:gitgutter_enabled = 1
endfunction
augroup gitgutter augroup gitgutter
autocmd! autocmd!
autocmd BufReadPost,BufWritePost,FileReadPost,FileWritePost * call GitGutter() autocmd BufReadPost,BufWritePost,FileReadPost,FileWritePost * call GitGutter()