Switching from TextMate to vim or emacs has been a trend on the rise. I’m riding the trend too, and it feels pretty good.
Coming from TextMate, there were a lot of things I missed. There were a lot of things I didn’t even realize existed.
This post is meant to help folks who are trying to make the same switch. It isn’t going to be the most extensive resource, but should point you in the right direction.
Oh, and just as a warning, one thing I’ve notice about reading vim resources is that they usually assume a certain level of familiarity with vim, and I don’t think this will post will be any different. If something is over your head, well, that gives you a new area to learn about :)
A Byte of Vim: This ebook starts at the very beginning, and walks you through pretty much every day-to-day type editing you’re likely to encounter. I’ve been using vim for several years, but I must have been using it pretty poorly, because I learned a lot from it.
Google: Seriously. Whenever there was something I didn’t know how to do, googling for
vim <insert thing here> worked nearly every time. Sometimes it took a few incantations.
Vim Wikia: In said google queries, this wiki showed up about 50% of the time. Lots of great tutorials, walkthroughs, and tips.
7 Habits For Effective Text Editing 2.0: Bram Moolenaar, one of the main authors of vim, gave this talk at Google. One of the takeaways I had from this is that it doesn’t matter which editor you use, as long as you are using it effectively. If you do something that feels repetitive, stop, find a better way, and then start using it. In another way, constantly refactor how you use your editor to improve efficiency.
Friends, Coworkers, and Family: You probably know some people using vim. They make a good resource as well. I primarily tap them as a resource for how they are using a particular command/plugin, or how they are achieving a particular goal. Be sure to do some research first, or you might get hit with a letmegooglethatforyou.
vim is amazingly extensible. There are also a lot of clever folks across the tubes. As a result of this, there are a lot of great plugins out there to assist your editing.
These are the plugins I’m using, and I’ll include any tweaks or mappings I’m using. These would go in your
rails.vim: For me, it’s all about being able to navigate around your project. For example, while editing a controller, you can easily switch to the functional test, or from a model to the unit test, and vice versa (
:A). If you have your cursor on a
render :partial, you can easily navigate to the partial (
gf). This is only a sampling of what it can do though.
NERD Commenter: Lets you easily comment out code. I made command-/ comment out code, kinda like in textmate.
NERD Tree: File navigation using a directory tree. I setup \d to toggle it being visible.
autoclose.vim: This will automatically close things like quotes, brackets, parantheses, etc. I’ve found it to be a little buggy at times, so I’m considering dropping it, or finding something else. YMMV.
bufexplorer.vim: vim keeps track of all the files you’ve edited, and has ways of navigating between them (
:bn for example). bufexplorer gives you a much more visual way of do this. It displays a window with all the files you’ve edited, you navigate to the file you want, and hit enter, and whoops, editing the file now. By default, it binds to \be.
endwise.vim: Kind of similar to autoclose, but more for structures you’d encounter while programming, such as if statements and class declarations.
fuzzyfinder_textmate: This is the texmate equivalent of ‘Go to File’. Pull it up, and start typing a filename. I bind it to \t (command-t opens a tab in MacVim).
allml: Gives you some ways to interact with the various HTML-like code that various programming languages / frameworks provide, like shortcuts to create
<% %> in ERB
matchit: vim has builtin support for ‘bouncing’ between parentheses using the % key. matchit extends it further to work with things like if blocks, class declarations, etc.
snippetsEmu: Emulates textmate snippets. I’ve found I don’t actually use this as much as I would have thought.
surround.vim: Tools for ‘surrounding’ your text. For example, add quotations, switch it to paraentheses, etc.
taglist.vim: vim has support for browsing by ‘tags’, which is to say, by method name, class name, etc. taglist gives you a way of seeing tags in the current file. It brings up a new window, which you can browse to the tag you want, and then automatically navigate to it. I’ve tried to make it act like ‘Go To Symbol’ in textmate. \T toggles the taglist, it gets focus, and then goes away after you navigate to something.
ack: Unfortunately not a packaged plugin, but you can just drop the code snippet (the second, updated one) in ~/.vim/plugin/ack.vim. This lets you search for stuff in your current directory, and gives you a way to browse the results. Kinda like textmate’s ‘Find in Project’. I made \F start the command off for you.
These are bits and pieces I’ve picked up along the way.
Not textmate specific, but you can map stuff to the command key in MacVim using M. For example,
<D-/> would be command-/
If you have problems with fuzzfinder_textmate being able to find the Ruby classes, I found just placing
~/.vim/ruby fixed the problem.
Insert hashrockets (
=>) while in insert-mode, just like in TextMate:
Indent and unident with
Switch to different tabs using command-1 through command-9:
Simplify window navigation
vim supports splitting a window vertically and horizontally, and then navigating between them. The default way kinda hurts my hands. Let’s reduce it to \s to split horizontally, \v to split vertically, and \w to cycle to the next window.
Other stuff, with less explanation
Whew. That was a lot longer than I had anticipated. Be sure to leave a comment if you have a question, or have better ways of doing any of this.