Add optional line highlighting.

This uses the `DiffAdd`, `DiffChange` and `DiffDelete` highlight groups.

Based on code by Tobias Pflug <tobias.pflug@gmail.com> (@gilligan).
This commit is contained in:
Andy Stewart
2013-02-27 12:22:31 +01:00
parent bd139b460b
commit e7247311f5
2 changed files with 38 additions and 7 deletions

View File

@@ -30,11 +30,17 @@ git clone git://github.com/airblade/vim-gitgutter.git
You don't have to do anything: it just works. 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 off with `:call DisableGitGutter()`
* turn vim-gitgutter on with `:call EnableGitGutter()` * turn on with `:call EnableGitGutter()`
* toggle it on/off with `:call ToggleGitGutter()`. * 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. You may want to add mappings for these if you use them often.

View File

@@ -9,6 +9,7 @@ let s:gitgutter_enabled = 1
function! s:init() function! s:init()
if !exists('g:gitgutter_initialised') if !exists('g:gitgutter_initialised')
let s:highlight_lines = 0
call s:define_highlights() call s:define_highlights()
call s:define_signs() call s:define_signs()
@@ -33,9 +34,15 @@ function! s:define_highlights()
endfunction endfunction
function! s:define_signs() function! s:define_signs()
sign define GitGutterLineAdded text=+ texthl=lineAdded if s:highlight_lines
sign define GitGutterLineModified text=~ texthl=lineModified sign define GitGutterLineAdded text=+ texthl=lineAdded linehl=DiffAdd
sign define GitGutterLineRemoved text=_ texthl=lineRemoved 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 endfunction
" }}} " }}}
@@ -46,6 +53,12 @@ function! s:is_gitgutter_enabled()
return s:gitgutter_enabled return s:gitgutter_enabled
endfunction 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() function! s:current_file()
return expand("%:p") return expand("%:p")
endfunction endfunction
@@ -253,6 +266,18 @@ function! ToggleGitGutter()
endif endif
endfunction 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 augroup gitgutter
autocmd! autocmd!
autocmd BufReadPost,BufWritePost,FileReadPost,FileWritePost * call GitGutter() autocmd BufReadPost,BufWritePost,FileReadPost,FileWritePost * call GitGutter()