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.
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.
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
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.
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
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
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
.vimrc file. Here’s my
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.
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.
- Here’s a Vim cheat sheet: