mirror of
https://github.com/airblade/vim-gitgutter.git
synced 2025-11-08 19:43:47 -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 next hunk: `:GitGutterNextHunk`
|
||||||
* jump to previous hunk: `:GitGutterPrevHunk`.
|
* 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.
|
See the customisation section below for how to change the defaults.
|
||||||
|
|
||||||
|
|||||||
@@ -407,31 +407,41 @@ function! GitGutterLineHighlightsToggle()
|
|||||||
endfunction
|
endfunction
|
||||||
command GitGutterLineHighlightsToggle call GitGutterLineHighlightsToggle()
|
command GitGutterLineHighlightsToggle call GitGutterLineHighlightsToggle()
|
||||||
|
|
||||||
function! GitGutterNextHunk()
|
function! GitGutterNextHunk(count)
|
||||||
if s:is_active()
|
if s:is_active()
|
||||||
let current_line = line('.')
|
let current_line = line('.')
|
||||||
|
let hunk_count = 0
|
||||||
for hunk in s:hunks
|
for hunk in s:hunks
|
||||||
if hunk[2] > current_line
|
if hunk[2] > current_line
|
||||||
|
let hunk_count += 1
|
||||||
|
if hunk_count == a:count
|
||||||
execute 'normal! ' . hunk[2] . 'G'
|
execute 'normal! ' . hunk[2] . 'G'
|
||||||
break
|
break
|
||||||
endif
|
endif
|
||||||
|
endif
|
||||||
endfor
|
endfor
|
||||||
endif
|
endif
|
||||||
endfunction
|
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()
|
if s:is_active()
|
||||||
let current_line = line('.')
|
let current_line = line('.')
|
||||||
|
let hunk_count = 0
|
||||||
for hunk in reverse(copy(s:hunks))
|
for hunk in reverse(copy(s:hunks))
|
||||||
if hunk[2] < current_line
|
if hunk[2] < current_line
|
||||||
|
let hunk_count += 1
|
||||||
|
if hunk_count == a:count
|
||||||
execute 'normal! ' . hunk[2] . 'G'
|
execute 'normal! ' . hunk[2] . 'G'
|
||||||
break
|
break
|
||||||
endif
|
endif
|
||||||
|
endif
|
||||||
endfor
|
endfor
|
||||||
endif
|
endif
|
||||||
endfunction
|
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
|
" Returns the git-diff hunks for the current file or an empty list if there
|
||||||
" aren't any hunks.
|
" aren't any hunks.
|
||||||
|
|||||||
Reference in New Issue
Block a user