Getting back to my vim roots with MacVim

Back when I got my MacBook last fall, I chose to go with TextMate for Ruby and Rails development, despite being a long vim user.

And it was good. I think it was deserving of the hype it usually receives from Ruby developers on Macs. Except for the paying for software thing... I still feel dirty about that.

Recently a friend ditched TextMate cold turkey in favor of vim, after seeing the cool and useful stuff coworkers could do with it. After seeing it myself, let's just say I'm going back to my roots.

If you're on a Mac, you just have to use MacVim (not to be confused with this MacVim). It's basically like gvim, except for Mac OS. Duh.

There are a lot really small, nice integration points and features I've been noticing.

  • Mac-like text navigation
    • option-left/right for navigating words
    • apple-left/right for start/end of line
    • apple-up/down for start/end of document
  • Shortcuts using the apple key
    • apple-s for saving
    • apple-n for new item
    • apple-a for select all. ggVG always felt annoying for doing this
  • Recent documents
  • Tabbing (apple-t creates a one, apple-w closes it)
  • Command line tool, mvim (similar to the mate command). It seems to aaccept the same options you'd expect of vim and gvim.

Similar to gvim using ~/.gvimrc, MacVim uses ~/.macvimrc. Personally, I've taken to putting everything in ~/.vimrc, and just creating a symlink.

I'm still working on replicating most of the functionality I came to find useful for Ruby development in TextMate, but I will keep you posted.

I'm also vaguely considering doing some screencasts with vim tips/tricks. One thing I'd want though, is a good way to show what keys are being pressed. I remember back in OS9 days, there was a utility for doing this, but I haven't found a modern equivilant.

Using Markdown in vim

My posts are written in Markdown, by using the wonderful BlueCloth library, as I discussed in this earlier post.

Considering this is my first Rails project, it definitely lacks a certain... sophistication. For example, posts are either published and live, or don't exist yet. And also, I don't have any autosave mechanism.

These two areas of want combined to make me a very sad panda one day. After writing up the post of the day, I may have restarted my computer, forgetting that I had a lovely work of writing in progress. Whoops. Got a little upset by that.

Until I have time to implement those two features, I found a suitable stop-gap: vim! So I've taken to simply writing stuff up in vim, and when it's ready, copy, paste, and publish. Easy peasy.

But where would vim be without some syntax highlighting? NOWHERE! Well, it's still pretty awesome regardless, but I don't think many would disagree that syntax highlighting is a bad thing.

While there isn't support out of box, some clever fellow wrote something up to do the trick. While I'm sure you could easily browse there to see how to do this, I'll reproduce it here as well.

Download this, and place it in ~/.vim/syntax/ (of course, creating it if it doesn't exist).

Now create, or add to ~/.vim/filetype.vim:

" markdown filetype file
if exists("did_load_filetypes")
 finish
endif
augroup markdown
 au! BufRead,BufNewFile *.mkd   setfiletype mkd
augroup END

And then to ~/.vimrc and/or ~/.gvimrc

 augroup mkd
  autocmd BufRead *.mkd  set ai formatoptions=tcroqn2 comments=n:>
 augroup END

I kind of feel like a plugin, or something, could take care of this for you, but I don't know enough vim voodoo to sure.

Now you have vim markdown goodness... Enjoy!