mirror of
https://github.com/airblade/vim-gitgutter.git
synced 2025-11-08 11:33:48 -05:00
Enable prev/next hunk commands to take a count.
This commit is contained in:
@@ -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.
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user