diff --git a/README.mkd b/README.mkd index 19ed387..25cab5c 100644 --- a/README.mkd +++ b/README.mkd @@ -427,6 +427,58 @@ Let's say, for example, you want to remove trailing whitespace from all changed ``` +#### Cycle through hunks in all buffers + +`]c` and `[c` jump from one hunk to the next in the current buffer. You can use this code to jump to the next hunk no matter which buffer it's in. + +```viml +function! NextHunkAllBuffers() + let line = line('.') + GitGutterNextHunk + if line('.') != line + return + endif + + let bufnr = bufnr('') + while 1 + bnext + if bufnr('') == bufnr + return + endif + if !empty(GitGutterGetHunks()) + normal! 1G + GitGutterNextHunk + return + endif + endwhile +endfunction + +function! PrevHunkAllBuffers() + let line = line('.') + GitGutterPrevHunk + if line('.') != line + return + endif + + let bufnr = bufnr('') + while 1 + bprevious + if bufnr('') == bufnr + return + endif + if !empty(GitGutterGetHunks()) + normal! G + GitGutterPrevHunk + return + endif + endwhile +endfunction + +nmap ]c :call NextHunkAllBuffers() +nmap [c :call PrevHunkAllBuffers() +``` + + ### FAQ > Why can't I unstage staged changes?