Skip navigation

Before you go any further, this isn’t about having gvim embedded in Outlook, or using it automatically as an external editor.

This method lets you use one keystroke to edit a mail in gvim and when you close gvim, it’s put back into the Outlook compose mail window.

You will need:

  • AutoHotkey, a keystroke mapping/scripting application
  • My script (below)
  • gvim for Windows

Method:

  1. Install AutoHotKey
  2. Install gvim
  3. Install my script into AutoHotKey (it appears at the end of this post). Note that my script has the gvim path hard-coded in and you may well need to change it.
  4. Configure your Outlook to use plain text for composing mail.
  5. Press Win-V with an Outlook compose window open and when the cursor is in the message pane

Serving suggestion:

  • Goes really well with Outlook QuoteFix
  • gvim will be opened with the contents of the message window
  • Edit your mail in gvim and when done, save and quit
  • Your edited message is put back into the Outlook message window.

Additional notes:

  • At the moment, this only works with one mail at a time, as the file for the mail is statically named. If you try Win-V in a mail while you have another already opened, Bad Things will Happen.
  • You may want to adjust your vimrc file so that it uses the “mail” filetype for editing; I also have a mail.vim file with macros and things in it which I tell it to load for this. I pinched it off the web, I’m sure you can find it. The required vimrc lines are below.
  • If the cursor isn’t in the message pane of the Outlook compose window when you press Win-V (or if it moves there before you close the gvim window), things will probably go wrong.
  • I’ve tested this with Outlook 2003, gvim 7.2 and AutoHotkey 1.0.47.06.

Here’s the optional vimrc line:

autocmd BufRead */outlook.txt :source $HOME/vimfiles/mail.vim

Here’s the script itself:

#v::
SetTitleMatchMode, 2
IfWinActive, Message (Plain Text)
{
    WinGet, ActiveWindow, ID
    SendInput ^a
    Send ^c

    clipboard = %clipboard%

    FileDelete, %TEMP%\outlook.txt
    FileAppend, %Clipboard%, %TEMP%\outlook.txt

    RunWait, C:\Program Files\vim\vim72a\gvim.exe %TEMP%\outlook.txt

    FileRead, Clipboard, %TEMP%\outlook.txt

    WinActivate, ActiveWindow
    Send ^a^v^{HOME}
}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>