How to remove white space at the end of each line while saveing /only for ft=roff/ ?

9 views
Skip to first unread message

tu...@posteo.de

unread,
Feb 13, 2021, 6:57:14 AM2/13/21
to vim...@googlegroups.com
Hi,

The subject nearly says it all:

When editing nroff or troff files white space at the end of a line
or on a line alone can be poisonous... :)
On other filetypes it is not neccessarily the case and harmless.

So I want to remove those white space only when saveing files in
roff/nroff/troff format.

What I accomplish so far is to remove white space for any kind
of file...but that's not exactly what I want.

How can I limit it to [nt]*roff filles only!

Cheers!
mcc


Gary Johnson

unread,
Feb 13, 2021, 4:13:50 PM2/13/21
to vim...@googlegroups.com
It should work to put the following autocommand in an after filetype
plugin file, i.e., in ~/.vim/after/ftplugin/nroff.vim:

autocmd BufWritePre <buffer> %s/\s\+$//

Alternatively, you could put this in your vimrc:

autocmd FileType nroff autocmd BufWritePre <buffer> %s/\s\+$//

Or, if some of your files were of type groff, this:

autocmd FileType groff,nroff autocmd BufWritePre <buffer> %s/\s\+$//

See:

help 40.3
help autocmd-buflocal
help BufWritePre
help FileType
help ftplugin-overrule

Regards,
Gary

Reply all
Reply to author
Forward
0 new messages