Version of GitGutterNextHunk that goes through all files
I would like to have a command that would go trough ALL the hunks in the project, not just the current file. Is this already somehow possible?
It's not built in but you could write a VimL function to wrap GitGutterNextHunk and go to the next buffer's next hunk when there are no more hunks in the current buffer.
I've added a section to the README explaining how to do this.
You'll need commit 8576f00 for it to work.
I think that is a good idea, and I think it's best if you map @airblade's suggestion to a capital C, such as:
nmap <silent> ]C :call NextHunkAllBuffers()<CR>
nmap <silent> [C :call PrevHunkAllBuffers()<CR>
This way you can still get the (sometimes preferred, if not usually) [c and ]c local buffer only behavior. This lower and uppercase convention is already useful in other areas of vim, and tpope really latches onto it with: https://github.com/tpope/vim-unimpaired/blob/d6325994b3c16ce36fd494c47dae4dab8d21a3da/doc/unimpaired.txt
Additionally, I don't really like the output when you're opening new buffers, or reaching the end hunk for a current buffer: "vim-gitgutter: No more hunks" (normal vim-gitgutter output/behavior), so I squelch that in this specific scenario (NOTE, you should probably reference the snippet from the README, and just note where I am putting silent! in the example below):
function! NextHunkAllBuffers()
let line = line('.')
silent! GitGutterNextHunk
if line('.') != line
return
endif
let bufnr = bufnr('')
while 1
silent! bnext
if bufnr('') == bufnr
return
endif
if !empty(GitGutterGetHunks())
normal! 1G
silent! GitGutterNextHunk
return
endif
endwhile
endfunction
function! PrevHunkAllBuffers()
let line = line('.')
silent! GitGutterPrevHunk
if line('.') != line
return
endif
let bufnr = bufnr('')
while 1
silent! bprevious
if bufnr('') == bufnr
return
endif
if !empty(GitGutterGetHunks())
normal! G
silent! GitGutterPrevHunk
return
endif
endwhile
endfunction
nmap <silent> ]C :call NextHunkAllBuffers()<CR>
nmap <silent> [C :call PrevHunkAllBuffers()<CR>
(It's just some additions of silent!)
Ok this would be a lot more useful if you could [C and ]C (cycle) through all of the hunks/changes in the repo, regardless if the buffer is already open.
I need this, and I'll work on it
Hey @shmup!
This is very late, but found a temporary solution that works quite well, while trying to find a way to cycle through all git changes/hunks across all edited files, please see below ->
- Set vim as default git editor in your terminal env file (i.e .zshenv)
export VISUAL=vim
export EDITOR="$VISUAL"
- Source your terminal env file (for me the file will be ~/.zshenv)
source ~/.zshenv // <-- change this to your terminal env file
- Add alias to ~/.gitconfig
[alias]
edit = !$EDITOR $(git status --short | awk '$1 ~ /^M|A|U/ {print $2}')
-
Add config from comment to your .vimrc -> https://github.com/airblade/vim-gitgutter/issues/362#issuecomment-434713641
-
Inside your repo directory where you made multiple changes to different files, you can now run command
git edit
This will open all the files that you edited inside your repo in vim buffers, and then you can use [C and ]C to cycle through all the changes/hunks
Hope this helps!