Here’s a quick tip on how to get rid of unwated trailing whitespace using vim.
Let’s say, I have the following code:
Open that file with vim. The following command deletes any trailing whitespaces.
Here’s the screenshot of the text after removing the whitespace:
\s finds whitespace (a space or tab).
\+ finds one or more occurences.
$ matches the end of line, finally
e flag means no error is displayed.
Ref: Remove unwanted spaces (warning: this reference page contains lots of ads, probably avoid opening it on a mobile device.)