Trailing whitespaces are a pain in the ass. Adding, deleting and modifying code can lead to invisible spaces at the end of the line. This is “bad” and useless.
Here comes Vim!
:%s/\s\+$//
A substitution command :%s/<search>/<substitute>/
Where the search is for trailing whitespaces \s\+$
and the substitute is “nothing”.
Writing this every time is too much effort, it’s a good idea to define a user command:
:command Deltw :%s/\s\+$//
Or better, add the line to your vimrc file:
command Deltw :%s/\s\+$//
now just typing the command Deltw deletes those annoyances.