Is there a
.vimrc setting to automatically remove trailing whitespace when saving a file?
Ideally (to be safe) I would like to only have this functionality for certain files, e.g.
My DeleteTrailingWhitespace plugin does this and, in contrast to the various simple
The plugin page contains links to alternatives; there's also a large discussion on the Vim Tips Wiki.
To keep cursor position use something like:
else cursor would end up at beginning of line of last replace after save.
Example: You have a space at end of line
Set up call to function using
One can also use, but not needed in this case, getpos() by:
This works (in the .vimrc file) for all files:
This works for just ruby(.rb) files: