I’ve just released a new Vim plugin to improve how I’ve been writing my e-mails. Every once in a while I remember I need to include someone in that e-mail I’ve started writing a few minutes before and that’s where using a normal text editor to write falls short: by default, there’s no integration between it and any sort of address book.
Note that I’m not talking about the usual workflow imposed by the command line clients, where you select the recipients and then you write your message. In this case, just setting up a query command (or analogous on your MUA of choice. I’m pretty sure it’s a fairly standard feature).
Well, this plugin’s intention is setting up a completion system that queries an external command using the same kind of tools that are used for managing your address book. As long as the output of such command is easily parseable, you can use it with this plugin. Here is how it works:
You setup the g:qcc_query_command option to the call to your address book (say, abook --mutt-query) and enable the completion on the filetype of your choice:
# Standard setup for mutt
let g:qcc_query_command = 'abook --mutt-query'
# You might consider using `omnifunc` if you have a completion
# system plugin like neocomplcache
au BufRead /tmp/mutt* setlocal completefunc=QueryCommandComplete
Now whenever you realise you have to fiddle with the headers that take e-mail addresses as parameters (From, To, Cc, etc), you can do it without leaving your Vim session. For example if you have the following in your line (| being the cursor position):
From: Foobar <foo@bar.com>, cai|
And then you trigger user completion (usually C-x C-u), Query Command Complete will go ahead and call abook --mutt-query cai and present the results back to you in that glorious wildmenu we all know and love.
There’s some configuration goodness also, so one can even adapt it to work with the most bizarre things:
-
g:qcc_line_separator: Separator for each entry in the result from the query. Default:'\n'. -
g:qcc_field_separator: Separator for the fields of an entry from the result. Default:'\t'. -
g:qcc_pattern: Pattern used to match against the current line to decide whether to call the query command. Default:'^\(To\|Cc\|Bcc\|From\|Reply-To\):'.
So, enough marketing. Give Query Command Complete a go and if you find any issues or want to contribute, check the project at Github. Have fun!