I’ve been using TextMate for a long time. It’s a great text editor that introduced a lot of really cool features like snippets and bundles. It is missing some features that I would consider standard though. Things like code folding and split windows. On top of that, TextMate 2 has been promised for the last few years and nothing has materialized.
I’ve tried out other editors before like BBEdit, jEdit, Coda and even plain ol’ TextWrangler, but I would always go back to TextMate after a week or so. Nothing seemed to be as slick or powerful as TextMate. I began to both love and hate TextMate for this. I knew I wanted something better, but there wasn’t anything I knew of that fit the bill.
Then I tried Vim. Actually, let me back up. I had tried Vim once for about 5 minutes a long time ago. When it first opened up, I tried typing and nothing was happening! I thought it was broken or installed incorrectly, so I dumped it and went back to TextMate.
Eventually my desire to find another, better editor came back a few months ago and this time I decided I wanted to really figure out this Vim creature people were cooing about. I learned about its different modes, and how you needed to be in insert mode in order to actually write your code. I couldn’t figure out why Vim’s normal mode wasn’t like every other editor I had tried before. I just want to write code, please! Then one day it finally clicked what kind of power Vim’s normal mode gives you.
Writing actual code is only a part of the whole coding experience. A lot of the time, you’re copying/pasting, fixing errors, jumping between files, etc. In an editor like TextMate and most others, you use your mouse and scrollwheel to move around, make selections and so on. This requires more hand movement than is needed.
A very simple example, say I wanted to move a line of code from one place to another. Say I need to copy line 60 to line 90. In TextMate, I would move my hand to my mouse, possibly use my scrollwheel to get to the area I want, move the mouse pointer to the line I want, triple click, then type Cmd-C, then click on the line I want to paste it, then type Cmd-V.
To be more fair, TextMate does have keyboard commands for this too. So to jump to a specific line, I type Cmd-L, then 60 and hit enter. Then type Cmd-Shift-L to select the whole line. Then type Cmd-C to copy it. Type Cmd-L, then 90, then enter. Then Cmd-V.
In Vim, in normal mode, I can jump to the line I want by typing :60, then type yy to yank (Vim-speak for copy) the line, type :90 to jump to the line I want to paste, then type P. It’s similar to TextMate here, but fewer keys and hand movements are needed. 17 keys for TextMate vs 12 for Vim (counting needing shift to get : ). With keymapping in Vim, that number can be even lower.
This is a simple example, so Vim isn’t that much quicker than TextMate here. Vim really starts to shine when you require much more complex movements and text manipulation. Plus it supports the two features TextMate still doesn’t after all these years: code folding and split windows.
When I first started using Vim, I was clumsy and made mistakes left and right. I couldn’t remember many of the basic movement keys, so I just stayed in insert mode most of the time. Every now and then I would venture into the scary normal mode. I’m sure a Vim jedi would’ve cringed if they were watching over my shoulder, but I kept at it and steadily became more comfortable and familiar with it.
I’m still not at the level a long-term Vim user will be at, but I’m definitely faster than I ever was with TextMate. You get spoiled really, really fast with normal mode and movement keys. I get pissed when I can’t use them in other apps. I’m forever trying to use Ctl-F/B in my browser.
I’ll wrap it up here by giving a few tips and pointers for those moving from TextMate to Vim.
First, download MacVim. It’s much more Mac-like and easier to use than Vim in the terminal. You can use Cmd-C and Cmd-V for instance, which eases the transition from another Mac editor to Vim.
Second, remap Ctl to your Capslock key. I never use the capslock key, and it’s much easier to reach with your pinky than the bottom-left ctl key.
Third, install these plugins:
A much easier way to manage your Vim plugins.
Uses ctags to create a list of all variables and functions in your currently viewed file, and lets you quickly jump from one to another
Gives you a directory tree you can nagivate through using either your keyboard or mouse
Makes commenting code quicker and easier
Mimicks TextMate’s snippets functionality
Makes surrounding code with various tags or brackets quicker and easier
Vim’s a bit different with how it handles copy/paste. YankRing makes it much easier to paste something you might have yanked a few changes ago.
Fourth, watch Derek Wyatt’s Vim screencasts, especially the beginner ones. Derek is easy to follow and listen to, is enthusiastic about what he’s showing you and knows his stuff. I learned a crap-ton of stuff just from his videos.
Fifth, bookmark these sites:
Sixth, do a Google search for “vimrc”. Check out what others are doing with their Vim config files. You can pick up some really handy settings, tricks and time-savers this way. I would highly recommend changing your leader key to “,” and mapping “,e” to edit your vimrc file. “,s” for quick reloading of the vimrc file.
Seventh, download and print out this Vim cheat sheet. I can’t tell you how many times I’ve used it over the last few months.
Lastly, don’t give up! Vim has a notorious learning curve that has defeated a lot of half-hearted forays into Vimland. Once you get over the initial hump, and you finally grok the power of Vim, there’s no going back.