Home > Mobile >  automate vim commands in git rebase
automate vim commands in git rebase

Time:07-08

After running git rebase -i master I always wish to write :2,50s/pick/squash/g in the vim window that opens. Is there a way to automate what will be written to vim?

This answer shows how to write vim commands from shell, but the problem is in my case the git commands open up vim, and it's not in my control.

CodePudding user response:

Create file

~/.vim/after/ftplugin/gitrebase.vim

try
    2;'} s/^pick/squash
    setlocal modified
catch
endtry

Must have filetype plugin on to work.

CodePudding user response:

You can define a key mapping in ~/.vimrc like this:

nnoremap  ,rb  :2,$ s/^pick/squash/<cr>

Then in the vim session started by git rebase, you just press ,rb if you want to squash all the commits.

Or define as a vim function:

function GitRebaseSquashAll()
    :2,$ s/^pick/squash/
endfunction

and call it with :call GitRebaseSquashAll().

  • Related