Enable prev/next hunk commands to take a count.

This commit is contained in:
Andy Stewart
2013-03-12 15:57:57 +01:00
parent 3f9cf5a44d
commit 64e9fac7df
2 changed files with 24 additions and 9 deletions

View File

@@ -54,7 +54,12 @@ Furthermore you can jump between hunks:
* jump to next hunk: `:GitGutterNextHunk`
* jump to previous hunk: `: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. For example:
```viml
nmap <silent> ]h :<C-U>execute v:count1 . "GitGutterNextHunk"<CR>
nmap <silent> [h :<C-U>execute v:count1 . "GitGutterPrevHunk"<CR>
```
See the customisation section below for how to change the defaults.

View File

@@ -407,31 +407,41 @@ function! GitGutterLineHighlightsToggle()
endfunction
command GitGutterLineHighlightsToggle call GitGutterLineHighlightsToggle()
function! GitGutterNextHunk()
function! GitGutterNextHunk(count)
if s:is_active()
let current_line = line('.')
let hunk_count = 0
for hunk in s:hunks
if hunk[2] > current_line
let hunk_count += 1
if hunk_count == a:count
execute 'normal! ' . hunk[2] . 'G'
break
endif
endif
endfor
endif
endfunction
command GitGutterNextHunk call GitGutterNextHunk()
command -count=1 GitGutterNextHunk call GitGutterNextHunk(<count>)
nmap <silent> ]h :<C-U>execute v:count1 . "GitGutterNextHunk"<CR>
function! GitGutterPrevHunk()
function! GitGutterPrevHunk(count)
if s:is_active()
let current_line = line('.')
let hunk_count = 0
for hunk in reverse(copy(s:hunks))
if hunk[2] < current_line
let hunk_count += 1
if hunk_count == a:count
execute 'normal! ' . hunk[2] . 'G'
break
endif
endif
endfor
endif
endfunction
command GitGutterPrevHunk call GitGutterPrevHunk()
command -count=1 GitGutterPrevHunk call GitGutterPrevHunk(<count>)
nmap <silent> [h :<C-U>execute v:count1 . "GitGutterPrevHunk"<CR>
" Returns the git-diff hunks for the current file or an empty list if there
" aren't any hunks.