How to get TextMate’s best features in Vim

And code more efficiently to boot

The debate over the best cod­ing text edi­tor will never end. In our office, the two biggest camps belong to TextMate and Vim. (We have one Komodo user, but we leave him alone.) There are things I love about both edi­tors, but Vim’s modal, mouse-free, keystroke-efficient phi­los­o­phy even­tu­ally won. At first I thought I was sac­ri­fic­ing my favorite TextMate fea­tures by choos­ing Vim, but Vim’s script­abil­ity in the hands of its clever com­mu­nity pro­vided solu­tions for every­thing I missed, plus count­less other bonuses.

Below is a list of awe­some Vim plu­g­ins I now depend on daily. Several are unapolo­getic TextMate knock­offs done in a more Vim-like way. Others are solu­tions to other cod­ing annoy­ances that only Vim could do. Try out a few below and see if Vim doesn’t steal your heart. (Also, if you’re new to Vim, I sug­gest installing Pathogen first to pre­vent headaches.)

Replace TextMate with Vim

NERDTree: Load a direc­tory tree on the left side of the screen. It will open high­lighted files on the cur­rent screen or in a new tab. (Pro tip: use the leader key to map some key­strokes to avoid hav­ing to type :NERDTree /path/to/my/code/ every time.)

Command-T: For addicts of TextMate’s ⌘-T smart-filtering file launcher, this plu­gin recre­ates that func­tion­al­ity using the leader key.

Snipmate: TextMate lovers can’t live with­out snip­pets, so why should Vim fans have to? In a few key­strokes, gen­er­ate HTML stubs, Python func­tions and other repet­i­tive, often-used bits of code. It’s stocked with snip­pet libraries for many lan­guages, and adding your own is easy.

Make Vim do things TextMate can’t

SuperTab: In insert mode, the Tab key will cycle through a list of words to auto-complete what you’re typing.

TComment: Typing gcc will tog­gle com­ments for the cur­rent line of code in nor­mal mode. In visual mode, gc tog­gles com­ments for any high­lighted rows. It works in most com­mon pro­gram­ming languages.

VIM Surround: A few key­strokes will add, change or remove brack­ets, quotes and HTML tags around the cur­rent word, line or high­lighted text. It takes some time to get the hang of this one, but it is flex­i­ble and powerful.

Vim Indent Guides: Trace tab inden­ta­tions in your code. Very use­ful for long nested if/else state­ments and loops, mak­ing sure you close HTML tags and for read­ing lengthy chunks of indented code.

Jellybeans: Jellybeans is a dark color scheme that’s easy on the eyes. Put it in your ~/.vim/colors/ direc­tory (or $HOME/vimfiles/colors in Windows) and run :colorscheme jellybeans or put colorscheme jellybeans in your .vimrc.

Of course, these plu­g­ins only scratch the sur­face of what Vim can do. If you want TextMate’s code col­laps­ing, Vim can do that. If you want to com­pile or run code you just wrote, no prob­lem. If you are a Pythonista who lives by PEP 8 for­mat­ting, there’s a plu­gin (and a .vimrc hack) for that. Point being: TextMate is great, but with a lit­tle pok­ing around, Vim can do as much or more, often with half the keystrokes.

7 comments

Skattcommented:

Command-T and Snipmate are very lim­ited, I don’t know NERDTree too much.

SuperTab: I love auto-complete in Textmate with ESC, if you want a list also have ALT+ESC.

TComment: In Textmate ⌘+/

VIM Surround is great.

I did not know Vim Indent Guides but looks nice.

The only thing I love in VIM is run­ning it on server side with SSH, the list of things in Textmate is much longer.

Josh Mockcommented:

2011-03-31, 12:38

I didn’t know about ⌘+/. Nice one, Skatt! Proof I was no TextMate power user. It seems to for­mat spac­ing wrong when tog­gling com­ments on and off though, unlike TComment. Also, SuperTab does show the list of auto-complete options, which is def­i­nitely impor­tant. And I highly rec­om­mend learn­ing NERDTree, espe­cially with the leader key hack I men­tioned. Navigating through the file list with the “j” and “k” keys is awesome.

I’m curi­ous what you find lim­ited with Command-T and Snipmate. Like I said, I was no TextMate power user, but both seem as pow­er­ful as the ‘Mate alter­na­tives for how I use them. I think with Command-T I had to add a line to my .vimrc to make it pull a file list from the proper con­text, but that was it.

Aside from the fea­tures, I love never hav­ing to use the mouse or arrow keys to get around. It saves so much time. Once all the key­strokes to do what I could do in TextMate were com­mit­ted to mus­cle mem­ory, there was no going back. Every time I open TextMate now, I end up acci­den­tally typ­ing a bunch of “j” and “k” char­ac­ters when I’m try­ing to nav­i­gate lines!

Now I’m curi­ous: what other things about TextMate would you miss?

Mattcommented:

2011-03-31, 13:31

The biggest thing that made me change from text­mate to vim was split panes. Also, large text viewing/editing.

Not to get all magic uni­corn babies eat­ing pop­si­cles on you guys, but I think VIM is the clos­est exist­ing thing to actu­ally inter­act­ing with your com­puter in a mean­ing­ful way and has influ­enced all of my inter­ac­tion habits since I adopted it. I feel as though I’m actu­ally com­mu­ni­cat­ing with my envi­ron­ment as opposed to just pok­ing it with an arrow pointed stick (ie mouse). That cou­pled with the afore­men­tioned perks in the post and a stel­lar com­mu­nity makes for what has been, imho, a great expe­ri­ence. I should really prob­a­bly get out more …

Seriously, though, give it a try … it looks decep­tively boring.

Josh Mockcommented:

2011-03-31, 15:53

Well said, Paul. Vim is both decep­tively bor­ing and has had a major impact on how I inter­act with my com­puter, to the point that I some­times copy text out of other edi­tors (or text areas in my browser), edit in Vim, then copy back over. MacVim’s “New MacVim Buffer with Selection” con­text option comes in handy there.

Phil Brasscommented:

2011-03-31, 19:15

I love me some NERDTree and split panes and ctrl+w,w. Also, I love the fact that I can turn on mouse sup­port in con­sole VIM, and it works over SSH through PuTTY. You can resize panes, use the mouse to make visual selec­tions, etc. You just have to remem­ber to use shift+mouse to send mouse input to PuTTY instead of VIM.

I’ve been a vi man since my uni­ver­sity days, when all the tal­ented CS stu­dents were split into vi and Emacs camps. I still respect Emacs, but vi’s modal sys­tem just makes so much *sense* to me.

In the Windows/.NET world, vi is a lit­tle tougher. As loathe as I am to admit it, Visual Studio offers a pretty good IDE, but the drop-in vi edi­tor replace­ments leave some­thing to be desired so I’ve mostly been going with­out of my favorite edi­tor for day-to-day cod­ing tasks, which is some­thing I hope to fix soon.

On a humor­ous note, you can read about my expe­ri­ences with a com­pany that asked me what my favorite edi­tor was: