I've been a vi and Vim user for a long time. As such, my most productive writing comes when I'm using my beloved modal editor. I'm also a long-time Mutt user, the main attraction being that I can edit my mail with Vim. Recently, I've started using GMail for my non-academic mail, so I can more cleanly drop into academic mode without distraction.

GMail is much better than Mutt at a couple of important things, the most obvious being search. Searching all your mail is a pain to set up in Mutt, but the simplest thing in GMail. Mutt is also quite slow opening large mailboxes, and it's impossible to save the same message in multiple 'places', as you can with GMail's labels.

But I really missed being able to write email in Vim. Good email communication requires chopping out stuff that's irrelevant to your reply, and snipping that stuff and keeping it readable is infinitely easier in Vim than in the pointy clicky world of a browser's textarea1.

While editing a long and involved email today, I pined on identica for Vim editing in GMail. I wasn't really expecting anyone to be able to suggest how I might achieve that but I quickly got a couple of useful leads. penryu suggested vimperator, which was supported by notjosh. Vimperator is an extension that makes Firefox behave in a kind of Vim-like way. I gave it a try but I couldn't work out how to use it as an editor for textareas2, and it seemed to have a bug (or possibly a conflict with the diigo toolbar) that meant I couldn't see anything I entered in Normal mode. So I ditched vimperator.

I had a small side journey looking at jsvi, a JavaScript reimplementation of vi, which I might revisit later to make a jQuery plugin, and extend that into a Habari plugin, but decided that was more than I wanted to do for the moment.

Next, screwtape and gavincarr suggested the It's All Text extension for Firefox. I managed to get that hooked up to MacVim (I couldn't get gvim to work) using the full path to the MacVim binary, in my case /Applications/MacPorts/MacVim.app/Contents/MacOS/MacVim. It seemed a little flaky in that it would only send the textarea to the buffer, and save edited content back, if MacVim wasn't open beforehand. That was okay because I use console Vim for everything else, and I can set MacVim to quit when the last window closes.

So, I was almost completely happy. The one down side was that I had been using Fluid to make a site-specific browser for GMail, which keeps my mail separate from my browser and seems to help keep Firefox's memory usage under control. But then, as I poked around MacVim's preferences I saw this.
MacVim's preferences
I'm willing to risk it for the moment. Enabling the external editor means I can have Fluid + GMail + Vim. Using the It's All Text Firefox extension means I can use Vim to edit wiki pages or write blog posts, like I'm doing with this one right now. And all that means I'm pretty happy.

[Update: I'm sure using MacVim as an external editor did work, but a day later edited text is no longer sent back to GMail. Sigh, perhaps I was imagining it. Now the closest I can get is cmd+A to select all the text in MacVim, close it, cmd+A to select all the text in GMail, then cmd+V to overwrite it with the edited text.]

  1. This is not your opportunity to say that it's even easier in emacs or textmate or notepad or whatever, because it's my blog and I like Vim, so there.
  2. Later, frt told me that you can achieve this with :set guioptions+=mT. I didn't try it, but I may revisit Vimperator in the future.