Skip to content

Instantly share code, notes, and snippets.

@garfvl
Last active July 26, 2020 14:59
Show Gist options
  • Save garfvl/e9b914a3c6000f4aff56894f43ee9c72 to your computer and use it in GitHub Desktop.
Save garfvl/e9b914a3c6000f4aff56894f43ee9c72 to your computer and use it in GitHub Desktop.
Display commit information during interactive rebase in (neo)VIM
" Display `git show <commit>` during interactive rebase in the preview window
function! PreviewCommitDuringRebase()
try
if getline(".") =~ '^\s*#'
throw "This is a comment line, do not preview"
endif
" get 2nd column == commit hash. Will fail if 2nd does not exists
let hash = split(getline('.'))[1]
let commitshow = systemlist("git show " . hash)
if v:shell_error != 0
throw "git show returned an error"
endif
" Launch preview edition
silent execute "noautocmd pedit Commit " . hash
silent wincmd P " jump to preview window
if &previewwindow
setlocal buftype=nofile " buffer should not be written
setlocal syntax=git " colors == git
wincmd L " put window to the right
call setline(1, commitshow) " push command output to the buffer
wincmd p " back to old window
endif
catch
" something gone wrong -> close preview
silent! exe ":pclose!"
endtry
endfunction
" Inside the `git-rebase-todo` file, try to launch the preview on cursor
" movement
:autocmd CursorMoved,CursorMovedI */.git/rebase-merge/git-rebase-todo :call PreviewCommitDuringRebase()
@garfvl
Copy link
Author

garfvl commented Jul 26, 2020

Can be combined wit tig rebase bindings:

.tigrc:

bind main R !git rebase -i %(commit)^
bind diff R !git rebase -i %(commit)^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment