I remember several years ago learning of a developer that used Vim as his primary editor. Who in the hell would do that? I thought. In my mind at the time, using Vim to write code was even more absurd than using Notepad.
Fast forward to today and I’ve been a happy Vim user for almost two years now. What changed?
First of all, I didn’t just wake up one day and declare “I need to learn Vim, now!” Vim started to get some buzz in the Ruby community and that piqued my interest. If respected peeps in the Ruby community were using it, there had to be something good there, I thought. After reading a few articles and watching a few screencasts, I started to “get it”—at least enough to decide to give it a fair try.
It didn’t take long to become completely smitten with the simplicity and power of Vim, and I never looked back. Why is that?
First things first—the default Vim installation that comes with your OS is not suitable as a development environment. If you try to use that, you will quickly be banging your head on your monitor shouting WTF. This is why I had no idea how good Vim is. Anytime I fired it up, it was very confusing and highly unusable, so of course I didn’t get it.
You have to add some key plugins and customizations before it becomes usable. I won’t go into details here, but I highly recommend starting with Janus—a minimal Vim working environment that includes all the most popular and essential plugins and mappings. As well, I started with MacVim, and relied on mouse support as a crutch in the beginning.
When I first started using Vim, I was slow as shit. At times it was terribly frustrating. This is a terminal program, so there’s no mouse, only keyboard commands. This initial learning curve is what turns most people off. Luckily, there are ways to add mouse ability to Vim, such as using MacVim. You should only do this in the very beginning though, because the real power of Vim shows up when you ditch the mouse and learn the keyboard commands.
As I persisted, something magical started to happen. After I had learned the basic commands and used them for awhile, they started to become muscle memory, and I no longer had to think about how to get to where I wanted to go or do what I wanted to do. I just thought it and my fingers just did what they needed to do, much like when I first learned to touch type.
After awhile, I stopped missing the mouse. Eventually, I become annoyed using any other text editor that relies on the mouse to get around.
Beyond the movement commands, there are all kinds of commands for inserting, editing, cutting and pasting, moving things around. As I learned these, I got even faster.
It almost starts to feel like a bit of a game. You know, up up down left, a+b, and then Mario does the Macarena (or something like that). Knowing the commands and being able to use them quickly and correctly is oddly rewarding.
Then there are the plugins. Vim has been around a long time and it is very stable. Lots and lots of very talented people use it. So naturally, there are lots and lots of high quality plugins to make Vim even more powerful.
At first, as I was just trying to learn the basics, I didn’t bother much with plugins.
Once I graduated from the basics, I began to look into and learn how I could make use of the many plugins that were already bundled with Janus. After awhile, there were several that I came to rely on completely. Here are a few…
Nerdtree provides a sidebar file browsing interface. Without it, there really isn’t a good way to navigate your project folder. Once you’re in the NerdTree window, there are all sorts of additional keyboard commands you can use to navigate. Those took some time to learn, but it was worth it.
Any good editor will have code completion capability. That is, you start typing
something and then hit
Snipmate adds additional functionality to the
def method_name end
You then type the method name, hit tab again and it puts your cursor into the method body where you can start typing the implementation. There are all kinds of time saving snippets for different languages and you can even add your own.
As a Rails developer, rails.vim is a must. It adds all kinds of useful
commands to navigate Rails projects, open corresponding test and implementation
files, an interface to the
rails command, and more.
If you’ve ever used TextMate then you’re likely a huge fan of Command-T for finding and opening files within your project folder. CtrlP adds this functionality to Vim.
I’ll stop there, but there are many more. I’ve found that whenever I think there should be an easier way to do something, I can almost always find a plugin for it.
Vim comes baked in with some really nice ways to manage working between multiple files at once. Split windows and tabs are awesome.
In Vim, you can divide your window horizontally or vertically to edit multiple files in the same view. I use this all the time to have a spec file open while I work on the implementation, or an HTML template open while I work on the SASS.
When I first started using Vim, I didn’t know it had tab capability. That is—the ability to have multiple tabs with files open in the same Vim session. When I’m working on a project, I often have several different files that I’m jumping around in. Tab support handles this nicely. And, with split windows, I can have multiple sets of multiple files open in different tabs. This is really nice.
I can customize Vim as much as I want. I can remap every single key command if I wanted to. I haven’t done that because that would be crazy, but Janus comes with several essential customizations baked in. I no longer use Janus (more on that at another time), but I have quite a bit in my own .vimrc to make Vim work just like I want it to.
While it wasn’t a huge factor in choosing to learn Vim, a nice bonus side effect is that I now am 100% comfortable editing text files in any server-side environment (because Vim or VI is baked in).
And, if OSX ever goes to shit and I need to jump ship, I’ll be able to continue using Vim as is. I used to say I could never work on Linux because of the tools I would miss, but now I don’t think I’d have a problem. I might actually prefer it for development work.
I could write a whole other post about tmux alone, and I should, but adding tmux to my toolbelt was a game changer. Tmux is a terminal multiplexer. In other words, it’s a tool to manage workspaces or “sessions” of multiple terminal instances. So before, I would have a code editor open and terminal window with multiple tabs that I would juggle through to do certain things like running tests, command line tools, viewing logs, etc. Now, my workspace looks like this:
I typically have either guard or some form of auto test running in the left pane, then middle pane is for Vim, and the right pane is for running command line utilities like git, rails, etc. I’ve been working like this for a few years now and I love this setup.
The best part about tmux is that other people can connect to and share a single tmux session. So whenever Jamie and I need to do any remote pairing, we fire up video chat and ssh into a tmux session where we can both share the same workspace—no matter where we are in the world. And it’s super fast because it only transfers text and keystrokes across the wire, not full on graphics like screen sharing would. Most of the time, you can’t even tell its not a local session.
A programmers #1 tool is their code editor. Most editors and tools come and go. Vim is almost 25 years old—it’s not going anywhere. Will I use Vim forever? Maybe, maybe not. For how much I’ve grown to love my setup, that would be perfectly fine with me.
Are you a Vim convert? I’d love to know what got you hooked… shoot me a comment and let me know.