Skip to content

Instantly share code, notes, and snippets.

@zhenghao1
Forked from c9s/.vimrc
Created August 29, 2012 08:48
Show Gist options
  • Save zhenghao1/3508729 to your computer and use it in GitHub Desktop.
Save zhenghao1/3508729 to your computer and use it in GitHub Desktop.
" Git rebase helper for:
" git rebase --interactive
"
" L - view commit log
" p - pick
" e - edit
" s - squash
" r - reword
" D - delete
"
" Cornelius <cornelius.howl@gmail.com>
fun! RebaseLog()
let line = getline('.')
let hash = matchstr(line,'\(^\w\+\s\)\@<=\w*')
vnew
setlocal noswapfile
setlocal nobuflisted nowrap cursorline nonumber fdc=0
setlocal buftype=nofile
setlocal bufhidden=wipe
let output = system(printf('git log -p %s^1..%s', hash,hash ))
silent put=output
silent normal ggdd
setlocal nomodifiable
setfiletype git
endf
fun! RebaseAction(name)
exec 's/^\w\+/'.a:name.'/'
endf
fun! g:initGitRebase()
nmap <silent><buffer> L :cal RebaseLog()<CR>
nmap <silent><buffer> p :cal RebaseAction('pick')<CR>
nmap <silent><buffer> s :cal RebaseAction('squash')<CR>
nmap <silent><buffer> e :cal RebaseAction('edit')<CR>
nmap <silent><buffer> r :cal RebaseAction('reword')<CR>
nmap <silent><buffer> d dd
endf
autocmd filetype gitrebase :cal g:initGitRebase()
@zhenghao1
Copy link
Author

Great gist for enabling VIM for git rebase interactive mode

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