To vim, or not to vim

As you might have read in my post about the tools I use, I’m a fan of using the command line. More and more GUI applications on my machines are getting replaced by one or more command line applications.

So far this has been a smooth ride and I’ll get to explaining why I prefer using the command line. There has always been one type of application that I just couldn’t get rid of and that’s my GUI text editor. Even though I’ve been a long time Sublime Text fan, making the switch to vim full time has always been tempting.

Vim screenshot

The main advantages that I see for using vim as my text editor is that it’s keyboard controlled only and comes pre-installed (as vi) on pretty much all Unix based operating systems. So wether I’m on my MacBook in Mac OS, or on my VPS or virtual machine running Linux, vim is pretty much always there.

It’s like learning a new language

My first few attempts at getting to know vim were absolutely miserable. Since vim is keyboard controlled only, there are a couple basic commands that you need to get in your system before you can even use it:

  • to move cursor left
  • l to move cursor right
  • j to move cursor down
  • to move cursor up
  • i to enter insert mode
  • esc to leave insert mode

You can move your cursor around using the arrow keys too, but since those are so far away from the home row on your keyboard, I recommend to stick to h, j, k and l from the start. This moving around mainly happens in the command mode, where you usually start in. As soon as you actually want to enter text, you go in insert mode. Right after you’re done entering text, you exit the insert mode again and back in command mode to navigate. This seems like a couple extra hoops to jump through at first, but the command mode will make navigating through files a breeze soon enough.

As soon as you’re used to these basic commands, you’ll learn new ones as you go. Just navigating the cursor one step at a time is painful, so you’ll soon want to be able to search through your files, jump to a specific line number and replacing certain parts of your file.

I continued to experiment learning new commands as I forced myself to use vim more and more. And I actually enjoyed it at times. But there were a lot more times where I hated vim, switched back to using Sublime Text again. Sometimes it just takes too much time and effort to get to know a new piece of software, especially when it’s rather complicated (well, ‘different’ is a better word) as vim is.

To learn the language, you need the grammar

Give up, it’s not for you. It crossed my mind more than once.

I think it was around one of these dark days in my journey to become a proficient programmer in vim, where I discovered the “The grammar of Vim” article:

For my first 15 years with Vim I tried to learn it the same way you might learn a foreign language from a phrasebook. I had learned everything in a disconnected way. Use j to move down a line. Use cw to change a word. Use yy to copy the current line into a buffer. You can get by this way, but it’s a very simplistic approach.

Advanced Vim users understand that Vim commands are a language unto themselves, and that the key to being productive is understanding Vim’s grammar. Pritzker accurately identifies that grammar as consisting of the following parts of speech: verbs, nouns, and modifiers.

This really made me see vim in a completely new way. It’s almost funny to see how wrong you can have been looking at a piece of software for a long time. The author had been in the exact same position as where I was. The article really spells out what most vim commands consist of and it’s basically as if you are learning grammar.

The road to become a vim master

Not everyone can become a proficient programmer in vim. But if you see the advantages to it and are determined to learn it, here are a couple tips (from one beginner to another):

  • Remove your current editor. It’s easier to get used to vim if you have to use it. If you really need to, installing your previous editor is quickly done too…
  • Read “The grammar of Vim“, at least three times.
  • Have a cheatsheet with the commands you are currently try to master. Start with about 10 commands and replace the ones you know with new ones you’d like to practice.
  • Try to apply the grammar to your commands (and on your cheatsheet). If you think there is a quicker way to do something, most times there is. Vim has been around for a long time, has a lot of resources and a Google query lead me to answers every single time.
  • Persevere. There is no other way.

I’m far from being a vim master, but I do feel that I can use it pretty much all day and am not less productive compared to using one of the editors I used before. It took me quite some time to get to this level. This is where the magic starts though. I’m still learning new tricks every day and am sure I’m becoming more productive every day. It’s baby steps, but that’s okay, I think I’ll be doing this programming thing for a little while longer.

2 replies on “To vim, or not to vim”

  1. Excellent post. I was cchecking continuously this weblog
    andd I am inspired! Exxtremely useful info specifically the final section :
    )I deal with such information a lot. I used to be seeking this certain info for
    a long time. Thanks and best of luck.

Comments are closed.