diff --git a/README.mkd b/README.mkd index 2e442d2..c19884f 100644 --- a/README.mkd +++ b/README.mkd @@ -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 ]h :execute v:count1 . "GitGutterNextHunk" +nmap [h :execute v:count1 . "GitGutterPrevHunk" +``` See the customisation section below for how to change the defaults. diff --git a/plugin/gitgutter.vim b/plugin/gitgutter.vim index bfa8797..970619c 100644 --- a/plugin/gitgutter.vim +++ b/plugin/gitgutter.vim @@ -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 - execute 'normal! ' . hunk[2] . 'G' - break + 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() +nmap ]h :execute v:count1 . "GitGutterNextHunk" -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 - execute 'normal! ' . hunk[2] . 'G' - break + 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() +nmap [h :execute v:count1 . "GitGutterPrevHunk" " Returns the git-diff hunks for the current file or an empty list if there " aren't any hunks.