I write my email in
vim, which dynamically inserts newlines after 72 characters.
This works nicely, breaking at spaces. However, is there a way to make it break at hyphens as well?
:help 'textwidth' is documented as:
Maximum width of text that is being inserted. A longer line will be broken after white space to get this width.
:help fo-table, it seems
there is only one option to change this:
m Also break at a multi-byte character above 255. This is useful for Asian text where every character is a word on its own.
Which brings us to a possible workaround – you can use the en dash (U+2013) or another non-ascii character instead of a normal hyphen (U+002D):
:set formatoptions+=m :inoremap - –
It's a bit ugly, but may work in your case.
A second – more complicated – solution can also be found in
When 'formatexpr' is set it will be used to break the line.
:help 'formatexpr' for
some details. Personally, I've never been able to get this to work quite right
for "live formatting" (as opposed to
gq formatting), but it should be possible
(I never tried very hard).
And lastly, you can use
to run an external command over the text. This is not ideal as you'll have to
run this manually every time, but it's an option (you could also just write a
Vimscript command for this though).