How to configure format=flowed for Neovim
Summary: A short guide on, how to configure Neovim to use format=flowed when writing emails
Created on:
-----
RFC 3676 specifies the email
format options flowed
. This format option allows for more dynamic and
user-friendly line breaks. On, e.g. technical mailing lists, it is common to
send Text/Plain emails and use something like 72 or 75 characters per line. The
character limit can be traced back to the days when monitors were smaller and
could only display 80 characters in each line. Nowadays, it is still common to
comply with this limit in order to be backwards compatible, improve
readability, and send patches on the mailing list without them being malformed.
The limitation of characters per line can lead to “embarrassing line wrap”. Furthermore, many people are used to having lines broken when they reach the border of their display window and not after 72 characters (also, on mobile devices, having hard line breaks can make it quite hard to read an email.)
When using format=flowed
, a line is flowed when it ends in a space, if it
ends in anything other than a space the line is fixed. A mail client that
supports this format option can dynamically format the line length, while
clients that don’t support this option can display the mail as if there would
only be hard line breaks.
The following shows how I configured my mail client, in this case aerc and
my editor Neovim which I use to read/write my emails. If you use a
different mail client, the basic idea should be the same: Your mail client
needs to add format=flowed
to the email header, and the editor needs to
format the text accordingly.
Configure aerc
I use aerc as my mail client, and setting
format=flowed
is relatively straightforward: In the aerc.conf
set
format-flowed=true
in the [compose]
section of the configuration.
Configure Neovim
To only use the formatting when writing emails, you need to figure out how the
editor can identify that you are writing an email. When using
aerc the filetyp
is set to mail
. Depending on
your mail program, this might differ.
- Create the directory
after/ftplugin
in your Neovim configuration. (e.g..config/nvim/after/ftplugin/
) - Create a Lua file with the same name as the
filetype
. (e.g..config/nvim/after/ftplugin/mail.lua
) - Insert into that file:
vim.opt.formatoptions = "awq"
The options formatoptions awq
mean (Neovim
documentation):
a -> Automatic formatting of paragraphs.
w -> Trailing white space indicates a paragraph continues in the next line.
q -> Allow formatting of comments with “gq”.
This will allow you to have the correct formatting for format=flowed
when
only writing emails, and it won’t interfere with other document formats.