For most of my development career, I have used heavyweight IDEs. A coworker convinced me to give Vim a shot about six months ago. In that time, it’s become my primary editor. Like any tool, there are pros and cons.

Motivation

About 12 years ago, I read the excellent book The Pragmatic Programmer. One of the tips given is to “Use a Single Editor Well”:

The editor should be an extension of your hand; make sure your editor is configurable, extensible, and programmable.

I’ve tried many editors over the years - UltraEdit, Notepad++, Sublime Text, and Atom, to name a few - as well as heavyweight IDEs like Eclipse and IntelliJ. These are all great tools, but I never learned any of them in-depth. At my current job at Constant Contact, I pretty much write CoffeeScript and JavaScript all day long. I used WebStorm for a while, but like other heavy IDEs, it felt like overkill.

First steps

Vim’s learning curve isn’t as bad as you might have heard. There is definitely a learning curve, but it’s manageable. Most Unix environments (including Mac OS X) have a vimtutor program that walks you through the basics. You only need to learn the essentials to get started - how to navigate with h, j, k, and l, and how to switch between normal and insert modes will get you up and running.

The next thing to learn is the myriad ways of navigating. w and b are crucial here. Anyway, this isn’t intended to be a Vim tutorial, so let me get to what I think are the pros and cons.

What I like about Vim

One of the things I like most about Vim is that I can edit and navigate files without having to take my fingers off of the keyboard. Not having to touch the mouse is a big time-saver. At first, it feels clunky selecting text with visual mode using the keyboard instead of just clicking and dragging to highlight with the mouse, but you get used to it quickly. (Of course, you can still use your mouse with Vim if you want.)

I also like some of Vim’s more advanced features - macros and registers, in particular. Macros make it really easy to perform and repeat tedious tasks. For example, I was doing some refactoring of some JavaScript code with ES2015 features. One of the things I had to do was replace all of the var foo = require('foo-library'); with import foo from 'foo-library'; By manually doing the work once, and recording a macro, it was simple to repeat the task for all of the other require statements.

Registers are great because you can copy and paste more than one piece of text. For example, any text that you delete goes into the * buffer. Any text that you type goes into the . buffer. When you copy (“yank”, in Vim parlance) text, you can specify which register you’d like to yank into.

The biggest advantage of Vim is its customizability/extensibility. You can tweak the editor exactly as you like it with the .vimrc file. Here’s my .vimrc file.

What I don’t like

As powerful as Vim is, there are still some things an IDE does better. For example, if I want to find everywhere in my code that calls a particular function, the best I can do is do a global search for the name of the function. This is okay - and lightning-fast if you use The Silver Searcher - but it will merely find everywhere where the function name appears. There’s no intelligent code analysis to find where the function is actually called as opposed to the name appearing in the text.

Compare this to IntelliJ’s “Find Usages” feature. Not only will it find everywhere a method is used, but it will break it down by usage type - references vs. calls, etc. That makes things much easier when doing a major refactor.

For JavaScript work, this isn’t really a huge deal to me. If I were working on a big Java application, I might fall back to using IntelliJ - with the IdeaVim plugin, of course.

My favorite Vim plugins

  • NERD Tree - A powerful file system tree explorer. It’s like the sidebar in Sublime or Atom.
  • ctrlp.vim - A fuzzy finder. Quickly open files or switch buffers.
  • vim-fugitive - Git integration for Vim. Use all of Git’s functionality without ever leaving Vim!
  • ag.vim - The Silver Searcher for Vim. Searches through your files lightning fast.
  • Syntastic - Syntax checking. Works with many different languages. For JavaScript code, it supports ESLint for linting.

Vim resources

  • Here’s a Vim cheat sheet:

  • As I mentioned above, most Unix environments have the vimtutor program.
  • Another fun way to learn Vim is with Vim Adventures.
  • Open Vim has a browser-based Vim simulator/tutorial.