From 562e6043d303a4553cf4068b670781df84d38670 Mon Sep 17 00:00:00 2001 From: Andy Stewart Date: Wed, 22 Feb 2017 10:03:04 +0000 Subject: [PATCH] Explain how to cycle through hunks in all buffers. --- README.mkd | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) 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?