Two Simple Steps Helped Me Learn Vim

I’ve wanted to learn Vim for a long time. But every time I tried to pick it up, I was overwhelmed with the endless possible keystrokes, perplexing modes, and odd navigation. I had been a Sublime Text 2 user for a long time (this is before 3). I ran through ‘vimtutor’ a couple of times, but even then, after I finished, I quickly forgot most of what I learned in the tutorial.

I knew that my lack of actually using it everyday was contributing to my slow progress. However, I was working for a consultancy and I needed to have a reasonable amount of efficiency in my daily programming, which I just didn’t have yet in Vim.

But, about six months ago, I decided to subscribe to Thoughtbot’s Learn program (now Upcase), and they had a series of videos all dedicated to learning Vim. The videos were very-well done and when I watched the videos, I saw how powerful Vim could be.

So, I decided to give it a shot again, but this time, I did two things differently, which dramatically helped my success.

#1 Use a Cheatsheet

This idea I think I got from Ben Orenstein (EDIT: Yep, found the article here and mentions the strategy below with the notecard) who mentioned using a cheatsheet. However, whenever I Googled “vim cheatsheet” I got images like this one…

vim cheatsheet

…which brought back nightmares of this…

periodic table

Those cheatsheets were overwhelming and lacking context, so they were of little help.

Another Strategy

I decided that every time I got stuck on how to do something in Vim, I would do a quick Google search to find out how to do it and then, keep track of those functions on a 3 x 5 notecard.

That’s right. An actual, physical, 3 x 5 notecard is my Vim cheatsheet. I keep it handy on my desk to reference it and add to it as I learn new things. Below is a photo of my current cheatsheet, because in reality, I’m believe I’m on iteration 3 of the cheatsheet. You could say I’m on version 0.3.

Adam DeLong Vim Cheatsheet

This was tremendously helpful, because early on, I often found myself trying to do the same things over and over in Vim and forgetting how they worked. Here’s a quick list of some of the things I would end up Googling…

Paste from the buffer in insert mode?
Comment out line in vim?
Indent a line in vim?
Copy two words in vim?

Of course, as I got better, I started to learn more “vim” efficient ways of doing things like the above. But writing down these steps helped me remember these individual steps.

#2 Complete Your Next Side Project in Vim

Like many curious developers, I often will have side projects that I work on during quiet nights and weekends. These projects are often done in technologies I’m already familiar with and don’t have the pressure of deadlines or hours to make which made them the perfect training ground to learn Vim.

So, after practicing and following along to the Vim videos, I decided to code my next project entirely in Vim. I will admit, I did not entirely adhere to this rule. I would sometimes get frustrated to the point where I would bust open ST2 in order to make a quick change that I had gotten stuck on. But for the most part, if I got stuck, I would Google, find the result and add it to my cheatsheet.

I noticed those times started to get less and less frequent. I started to feel really comfortable with the new Vim workflow. I decided to give it a try at work. I knew that at that point, if I ever got stuck, I could always Google and probably figure out the solution.

Sure enough, I started using Vim for work and before I knew it, it had been a week and I hadn’t opened ST2 once.

Additional Tips for Vim

While those steps were the most crucial to helping me learn Vim, here are a couple of additional tips.

  • Watch the talks on Vim from Ben Orenstein and Chris Hunt and learn from their dotfiles on github. Ben Orenstein and Chris Hunt
  • Use the ‘ctrlp’ plugin for file searching
  • ‘autoindent’ is your friend
  • I am a Drupal developer. I started using Vim about 2 years ago. I was working on a project and I had to change its core. Everytime I opened one of its file (which is ~4000 lines of code) in Eclipse my system hangs. My system was Core 2 Duo with only 2GB RAM, and Eclipse took 1GB just to open a file. I did not knew about Sublime text editor that time, and I switched to Vim (thanks to my ignorance I am the most proficient Vim user among my colleagues and *proud of that*).

    Vim is so much developer-friendly, and thanks to its vibrant community you can find plugins for almost anything.

    Good to know about your experience in learning Vim. Happy coding!!

  • bob

    Nice! Getting started on side projects if a very good idea. Then when you feel more comfortable, you can start using at work for simple tasks. And then…

    Here are some resources that can help getting deeper in vim:

    * http://vimcasts.org – tons of screencasts
    * http://vimawesome.com – tons of plugins sorted by populatiry / genre

    Also I found very useful to have my own wiki to host various oneliners or tip’n’tricks. Just the fact of writing your own shortcuts, and sorting them how you like is anchoring your memory:

    http://imgur.com/my7lJJG

  • I agree with your experience learning Vim. It may be a bit overwhelming at the start (ok, maybe not a bit) but once you start getting the hang of it, it becomes almost natural. I often find myself using Vim commands on a co-worker’s ST2 editor, for instance.

    Learning vim for me was in phases.
    I had to first learn how to close the Vim properly without doing something nasty to the text I was trying to edit.
    Then entering and leaving ‘Insert mode’ as well as common motions, ‘hjkl’, till it stuck.
    Then for more advanced commands, I used google and the #vim IRC channel on freenode quite a lot. I can say that I’ve written whole projects entirely in Vim but there’s still so much more to learn about the Editor; an exciting thought!

  • amcdawes

    I’ve been using vim for over 15 years, and still learned a lot from this great reference: vim movement wallpaper, http://naleid.com/blog/2010/10/04/vim-movement-shortcuts-wallpaper

    It is very handy to have on a desktop and layer a window over it with some transparency. Don’t even have to look away from the screen.