Vim fu

Becoming a Vim master starts with being a Vim beginner

One of my tech passions is Vim and its philosophy. I’m even writing this post using it. To become better at something, whether it be martial arts, playing an instrument or programming, you need to be consciously striving to improve. The old cliché “Perfect practice makes perfect” is no less correct just because it’s overstated. Just repeating a movement or series of movements with the hope that one day you’ll wake up the best at it is not the way to do it.

I think using Vim (or an offshoot like IDEAVim in Intellij’s IDEA) is going to make for a more efficient and productive developer. I could think of a million reasons why but I’m planning on just writing a series of posts with simple Vim tips that might demonstrate my reasoning.

Basic macros

q is used to start recording a macro, followed by a designation for the macro for playing it back e.g. qa will create macro named “a”. Press q again to stop recording and @a to play the macro at any time. Why is this useful? If I have a file that has 1000 lines and I need to format each line in the same way, I can record a macro for one line (and move down a line) and finish the recording. 1000@a will play the macro a thousand times and file is done. Magic. The Vim ethos of making commands repeatable combined with macros can create some very powerful functionality. Bonus tip: @@ plays the last macro again.

More to come…

Note this post and and future ones in this series are in category “Vim”. Keep an eye out for updates. If you have no idea what this Vim thing is then have a look over at The Official Vim Site

Leave a Reply

Your email address will not be published. Required fields are marked *