Getting serious with Vim

I originally learned Vim for the same reason as many other people do; to edit configuration files on a web server. As such, I quickly learned that if I pressed i, I could type stuff, and Esc followed by :wq would save a file, and return me to the (relative) safety of the shell. For a great many years, that was all I felt like I needed to learn. No movement commands other than the cursor keys, and the concept of ‘modes’ was certainly lost to me.

I considered this fine and dandy for a long time, and did all of my ‘serious’ text editing in TextMate, which I felt was the pinnacle of productivity for a couple of years. However, after a significant period of inactivity, I felt the collective restlessness over the lack of updates, and was very disappointed by TextMate 2 when it finally did land, I decided to what else was out there. While there were a couple of options, nothing really stuck out as being a major step ahead of TextMate.

It was around this time that I watched the Peepcode Play By Play screencast with Gary Bernhardt, which was a revelation to me. The sheer efficiency with which he used it, and the raw speed at which he edited and traversed the project was stunning. I had no idea that Vim could be used so deftly, and that my ignorance was tremendous. While obviously typing isn’t the bottleneck in programming, I suddenly felt embarrassed at how little I knew of any text editor, Vim or otherwise. Given the ubiquity of Vim, I figured it made sense to try learning it.

The first step I took towards becoming comfortable with Vim was to check out the Peepcode screencasts on Vim. They focus a lot on configuration, the all-important movement commands, and getting more productive. I highly recommend them if you’ve had trouble getting to grips with basic through to intermediate Vim in the past, personally, I found them to be a huge boon.

After watching the PeepCode videos, and dipping my toes into using Vim for projects, I decided to start a project using Vim as my only text editor, to ingrain what I had learned. I expected to struggle, however, I quickly ascended the learning curve, and gained the much lauded ‘muscle memory’ which many Vim users speak of. I finally felt like I had a text editor which had become an extension of my hand. It felt great!

One thing that is very striking about Vim compared to many GUI-heavy text editors is the level to which it can be customised, both with plugins, and key remapping to suit personal style. Initially I installed far too many plugins, not understanding a number of them, before whittling down to a bare configuration, and slowly installing plugins as I realised where they would be useful. The Vim plugin world is extremely active, but there are some real heroes within it, including Tim Pope and Kana Natsuno, whose plugins are superb.

I felt so comfortable with what I had learned, and I had customised Vim enough that I felt ready to remap the cursor keys to do nothing in normal mode, forcing myself to use the h, j, k and l keys in their stead. This felt like a major step, and again, I expected a significant drop in efficiency while I learned to use them. To my great surprise I had almost completely stopped using the cursor keys while in normal mode already, and the transition was absolutely minimal.

One of the great things at this point was being able to show off to my co-workers! I think the vast majority of people who use Vim casually are completely unaware of the word completion functionality (I certainly was), so showing them how they can simply type Ctrl+P in insert mode to complete a word, was very rewarding!

Last week I attended a Vim Masterclass run by Vimcasts Drew Neil. It was really excellent (I highly recommend going if there is one near you in the future). The class focussed on using Vim for comfort, rather than trying to keep keystrokes to an absolute minimum (although often the two are somewhat related), and encouraging us to think about the interaction between modes, and how they can be used to our advantage. I highly recommend his book Practical Vim, as it covers much of the same material as the class.

I still have a lot to learn. Many of the lessons taught in Drew’s masterclass will take some time to sink in, and I still have tons to learn (namely Vimscript), but I am excited to learn it, and I am delighted that I have found my ideal text editor!

A handful of my favourite ‘tips’

  1. :w !sudo tee % – write to a file with superuser permissions
  2. Word or line completion in insert mode with Ctrl+P and Ctrl+X Ctrl+L respectively
  3. :!mkdir -p %:h to create the parent directory when you are editing
  4. gk and gj to move up and down the display lines of a document (incredibly useful where a long line has been wrapped over several display lines)
  5. gf open the file under the cursor (for example, an included file)


Here are some resources which I recommend if you want to get serious with Vim, from far better teachers than I:

  1. Practical Vim: Edit Text at the Speed of Thought – Drew Neil of Vimcasts excellent book
  2. Steve Losh’s “Coming Home to Vim” – Great guide from a thoughtful mind
  3. Peepcode’s “Smash into Vim” – Videos for the hard of patience
  4. Destroy All SoftwareExpert Vim usage screencasts
  5. MacVim – A lovely native Vim binary for the Mac
  6. “Vim: From Essentials to Mastery” – A great conference video covering Vim history and usage tips