Saturday, February 13, 2021

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

On 2021-02-13, tuxic wrote:
> 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!

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

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20210213211352.GC16915%40phoenix.

No comments: