mirror of
https://github.com/airblade/vim-gitgutter.git
synced 2025-11-09 03:53:47 -05:00
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:
14
README.mkd
14
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 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.
|
||||||
|
|
||||||
|
|||||||
@@ -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()
|
||||||
|
|||||||
Reference in New Issue
Block a user