mirror of
https://github.com/airblade/vim-gitgutter.git
synced 2025-11-08 11:33:48 -05:00
Add functions to jump between diff hunks.
This commit is contained in:
committed by
Andy Stewart
parent
8ed5c48b63
commit
04a72e9e3c
@@ -44,6 +44,11 @@ And you can turn line highlighting on and off (defaults to off):
|
|||||||
* turn off with `:call DisableGitGutterLineHighlights()`
|
* turn off with `:call DisableGitGutterLineHighlights()`
|
||||||
* toggle with `:call ToggleGitGutterLineHighlights()`.
|
* toggle with `:call ToggleGitGutterLineHighlights()`.
|
||||||
|
|
||||||
|
Furthermore you can jump between hunks:
|
||||||
|
|
||||||
|
* jump to next hunk: `:call GitGutterNextHunk()`
|
||||||
|
* jump to previous hunk: `:call GitGutterPrevHunk()`.
|
||||||
|
|
||||||
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.
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -237,8 +237,8 @@ function! GitGutter()
|
|||||||
if g:gitgutter_enabled && s:exists_current_file() && s:is_in_a_git_repo() && s:is_tracked_by_git()
|
if g: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 s:hunks = s:parse_diff(diff)
|
||||||
let modified_lines = s:process_hunks(hunks)
|
let modified_lines = s:process_hunks(s:hunks)
|
||||||
let file_name = s:current_file()
|
let file_name = s:current_file()
|
||||||
call s:clear_signs(file_name)
|
call s:clear_signs(file_name)
|
||||||
call s:find_other_signs(file_name)
|
call s:find_other_signs(file_name)
|
||||||
@@ -276,6 +276,30 @@ function! ToggleGitGutterLineHighlights()
|
|||||||
call s:update_line_highlights(s:highlight_lines ? 0 : 1)
|
call s:update_line_highlights(s:highlight_lines ? 0 : 1)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! GitGutterNextHunk()
|
||||||
|
if g:gitgutter_enabled && s:exists_current_file() && s:is_in_a_git_repo() && s:is_tracked_by_git()
|
||||||
|
let current_line = line('.')
|
||||||
|
for hunk in s:hunks
|
||||||
|
if hunk[2] > current_line
|
||||||
|
execute 'normal! ' . hunk[2] . 'G'
|
||||||
|
break
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! GitGutterPrevHunk()
|
||||||
|
if g:gitgutter_enabled && s:exists_current_file() && s:is_in_a_git_repo() && s:is_tracked_by_git()
|
||||||
|
let current_line = line('.')
|
||||||
|
for hunk in reverse(copy(s:hunks))
|
||||||
|
if hunk[2] < current_line
|
||||||
|
execute 'normal! ' . hunk[2] . 'G'
|
||||||
|
break
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
endif
|
||||||
|
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