Reputation: 6043
I highlight trailing whitespace for all files using this snippet in my vimrc
:
hi link TrailingWhiteSpace Search
au BufWinEnter * let w:twsm=matchadd('TrailingWhiteSpace', '\s\+$')
" Setup a toggle.
nnoremap <silent> <Leader>w
\ :if exists('w:twsm') <Bar>
\ silent! call matchdelete(w:twsm) <Bar>
\ unlet w:twsm <Bar>
\ else <Bar>
\ let w:twsm = matchadd('TrailingWhiteSpace', '\s\+$') <Bar>
\ endif<CR>
However I'm also writing emails in Vim because I use Mutt and using format=flowed to avoid hard line breaks. I've set this in my muttrc
set text_flowed=yes
and have this in my vimrc
augroup ft_mail
au!
au FileType mail setlocal fo+=aw
augroup END
to achieve that.
This gives me visual line breaks in Vim but doesn't introduce hard line breaks in the actual emails. However this setup (and emails in general) tends to have trailing whitespace in various place, which I'm fine with, so I would prefer not to highlight it.
How can I stop trailing whitespace when writing emails? I'm open to better ways to highlight whitespace if that helps the answer.
Upvotes: 0
Views: 127
Reputation: 172530
You could introduce a buffer-local b:IgnoreTrailingWhitespace
variable, set that in ~/.vim/ftplugin/mail.vim
, and consider it (via exists('b:IgnoreTrailingWhitespace')
in your autocmds.
Alternatively, have a look at my ShowTrailingWhitespace plugin; it has that functionality built in and even ships with an exception for the mail
filetype (among others)!
Upvotes: 2