Using Vim as Email Editor together with mutt

Vim is a great editor and can also used for writing Emails. I am using mutt as my mail user agent and have configured several scripts for using Vim with mutt.

Configuring Vim


You need to configure Vim to support filetype plugins. Vim by default can detect mails when used from vim and will set the buffers filetype to mail and load mail specific scripts. For this make sure, your .vimrc contains at least a statement such as

filetype plugin on

That's already it. All the coming scripts, if not explained otherwise can now be placed into a directory ~/.vim/ftplugin/mail and Vim will automatically load them, when using Vim for writing Emails.

    Formatting Text automatically

    format.vim (html)

    This file let's Vim guess what kind of text you are writing and sets some formatoptions. So it sets different formatoptions, depending on whether you are editing the header of the Email, are fixing some quotations or edit a patch.  Credits go to Teemu Likonen.


    Automatic formatting of Mails

    posting.vim (html)

    Allows to automatically format your mail (e.g. strip quoted signatures, add Greeting, change and clean subject).
    Note: For using the Greeting feature, make sure you define the variables b:Signoff and b:Name.
    I explicitly set those variables in my .muttrc like this:

    set editor='vim --cmd "let b:Signoff=\"Grüße\"|let b:Name=\"Christian\""'

    Using folder-hooks, you can configure those variables to your liking, e.g. have english greeting when opening a mailinglist folder.

    Check out the mappings, that are defined in this script:
    \mdq   Deletes quoted signatures
    \mds    Deletes old subject
    \mct    Change the subject (adds the (was...) around it)
    \mcs    Clean subject (removes the (was....) part)

    Querying your adressbook

    lbdbq.vim (html)

    This is Vim-Script Plugin 1757  and lets you use lbdbq for querying various adressbooks. I mainly use it for querying abook and mutt's aliases file. Simply enter the search term and press \lb. Vim will query lbdbq for your search-term and present a dialog of adresses to use.

    Omni-completion for adresses

    lbdbq_complete.vim (html)

    This is an addon to the lbdq.vim script from above. It adds a omni-completion, so you can enter search-terms and press <Ctrl-X><Ctrl-U> in insert mode to have Vim display a small completion menu for the adresses available.

    Displaying the From in the Statusline

    stl.vim (html)

    Displays the Author of the Email to whom you are responding in the statusline. Nothing more to say.

    Check for missing Attachments


    Use the Vim Plugin CheckAttach (github)
    Reminds you, if you want to attach files to your mails and you can select the files using filename completion. You can also attach files manually using the :AttachFiles command. Supports ranger as file browser.