DEV Community

Kahlil Lechelt
Kahlil Lechelt

Posted on • Originally published at kahlillechelt.com on

Vimming in the Squasher: How to Squash Your Commits with VIM

Whenever I use git rebase -i to squash commits, Git opens the squasher (that’s how I just named the text view for the interactive rebase) in VIM.

My knowledge of vimming is not very great so I used to just type i and then inch around with the arrow keys and delete character by character in order to delete the word “pick” a bunch of times and then type “squash” a bunch of time.

Of course that was incredibly annoying, so I finally looked up how to vim in the squasher and it is glorious. So here is how you do it:

First, move to the line with the first commit you want to squash, which is typically the second one.

Then, enter into something called visual block mode (WTF?! What does that even mean?) by hitting ctrl + V. Something magical happens: when you move the curser it blocks out every character you move over with white and if you move down it will cover as many characters you covered in the line above. It looks like blocks. So I guess that’s where the “visual block” comes in 😅.

Select all the rows you wish to squash while visually blocking out the word “pick”.

Now, more magic: hit C and type the word “squash”, after that hit esc and see the word “squash” applied in all places that were “visually blocked out”.

If you only could exit VIM at this point, you would actually successfully squash all these commits. A boy can dream, right?

Top comments (0)