diff --git a/README.mkd b/README.mkd index f7eebc7..2d75fe8 100644 --- a/README.mkd +++ b/README.mkd @@ -30,11 +30,17 @@ git clone git://github.com/airblade/vim-gitgutter.git You don't have to do anything: it just works. -You can also: +You can explicitly turn vim-gitgutter off and on: -* turn vim-gitgutter off with `:call DisableGitGutter()` -* turn vim-gitgutter on with `:call EnableGitGutter()` -* toggle it on/off with `:call ToggleGitGutter()`. +* turn off with `:call DisableGitGutter()` +* turn on with `:call EnableGitGutter()` +* toggle with `:call ToggleGitGutter()`. + +And you can turn line highlighting on and off (defaults to off): + +* turn on with `:call EnableGitGutterLineHighlights()` +* turn off with `:call DisableGitGutterLineHighlights()` +* toggle with `:call ToggleGitGutterLineHighlights()`. You may want to add mappings for these if you use them often. diff --git a/plugin/gitgutter.vim b/plugin/gitgutter.vim index e4f607a..230d152 100644 --- a/plugin/gitgutter.vim +++ b/plugin/gitgutter.vim @@ -9,6 +9,7 @@ let s:gitgutter_enabled = 1 function! s:init() if !exists('g:gitgutter_initialised') + let s:highlight_lines = 0 call s:define_highlights() call s:define_signs() @@ -33,9 +34,15 @@ function! s:define_highlights() endfunction function! s:define_signs() - sign define GitGutterLineAdded text=+ texthl=lineAdded - sign define GitGutterLineModified text=~ texthl=lineModified - sign define GitGutterLineRemoved text=_ texthl=lineRemoved + if s:highlight_lines + sign define GitGutterLineAdded text=+ texthl=lineAdded linehl=DiffAdd + sign define GitGutterLineModified text=~ texthl=lineModified linehl=DiffChange + sign define GitGutterLineRemoved text=_ texthl=lineRemoved linehl=DiffDelete + else + sign define GitGutterLineAdded text=+ texthl=lineAdded linehl=NONE + sign define GitGutterLineModified text=~ texthl=lineModified linehl=NONE + sign define GitGutterLineRemoved text=_ texthl=lineRemoved linehl=NONE + endif endfunction " }}} @@ -46,6 +53,12 @@ function! s:is_gitgutter_enabled() return s:gitgutter_enabled endfunction +function! s:update_line_highlights(highlight_lines) + let s:highlight_lines = a:highlight_lines + call s:define_signs() + redraw! +endfunction + function! s:current_file() return expand("%:p") endfunction @@ -253,6 +266,18 @@ function! ToggleGitGutter() endif endfunction +function! DisableGitGutterLineHighlights() + call s:update_line_highlights(0) +endfunction + +function! EnableGitGutterLineHighlights() + call s:update_line_highlights(1) +endfunction + +function! ToggleGitGutterLineHighlights() + call s:update_line_highlights(s:highlight_lines ? 0 : 1) +endfunction + augroup gitgutter autocmd! autocmd BufReadPost,BufWritePost,FileReadPost,FileWritePost * call GitGutter()