Transitioning to Mutt (and Vim!)

mutt linux gmail imap vim

Sun Jun 05 16:56:53 -0700 2011

I’ve finally decided to attempt a real transition to the Mutt email program after years of flirting with the idea and making short, hesitant attempts that amounted to nothing. This time I’m giving it a fair shake as part of an overarching effort to move toward more fully keyboard-driven computer interaction that has involved replacing other components with Vim and Xmonad.

I currently have all of my mail flowing through Gmail in one way or another, accessing it regularly via the web on my laptop, and the official Gmail application for Android. So the first step in this transition is to use mutt as an IMAP client for Gmail, leaving any server-related work for later stages.

Fortunately, Google turned up several on-target results for just that scenario. After some trial-and-error one of them had the goods: Using Gmail with Mutt, the minimal way (IMAP update). The folder names were an especially great detail as it solves the problem of IMAP/Drafts and so forth labels being created in Gmail by prefixing them with Gmail.

I also managed to get Gvim hooked up to it after a little trouble initially. Mutt automatically launched Gvim for new message composition because (I assume) it checks for the VISUAL and EDITOR environment variables (which are set to Gvim and Vim on my system) however the headers were not present in the buffer and saving an attempted message would come to nothing. In fact Mutt would print “Aborted unmodified message” in its status bar as soon as Gvim was launched.

The solution was to set the editor in .muttrc, like so:

set editor="gvim -f"

The -f option tells Gvim that it should stay tethered to the shell it was spawned from rather than forking and detaching from it.

But that’s not all, I also found a few helpful nuggets here: Mark’s Mutt Fan and Tip page. After which the set editor line in my .muttrc file was replaced with:

set edit_headers  
set editor="gvim -f +/^$ ++1"

I also added Mark’s syntax highlighting suggestion:

" set up syntax highlighting for my e-mail  
au BufRead,BufNewFile .followup,.article,.letter,/tmp/pico*,nn.*,snd.*,/tmp/mutt* :set ft=mail

And finally, I happened across an aging mailing list entry with a smart tip: define an email-specific configuration file for Vim/Gvim. Unlike the example given, I’m using -S rather than -u, to preserve the rest of my configuration.

So finally the set editor line in .muttrc looks like:

set editor="gvim -f +/^$ ++1 -S ~/.mutt_vimrc"

A-muttering I will go!

blog comments powered by Disqus