Add functions to jump between diff hunks.

This commit is contained in:
Tobias Pflug
2013-02-28 09:56:41 +01:00
committed by Andy Stewart
parent 8ed5c48b63
commit 04a72e9e3c
2 changed files with 31 additions and 2 deletions

View File

@@ -44,6 +44,11 @@ And you can turn line highlighting on and off (defaults to off):
* turn off with `:call DisableGitGutterLineHighlights()`
* 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.

View File

@@ -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()
call s:init()
let diff = s:run_diff()
let hunks = s:parse_diff(diff)
let modified_lines = s:process_hunks(hunks)
let s:hunks = s:parse_diff(diff)
let modified_lines = s:process_hunks(s:hunks)
let file_name = s:current_file()
call s:clear_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)
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
autocmd!
autocmd BufReadPost,BufWritePost,FileReadPost,FileWritePost * call GitGutter()