In the .vimrc file, add the following lines ( here ^M is a special character for the return carriage created using CTRL+V):
%s/^ \+ $//
those functions call then be called within vim typing:
some Explanation of the function removeWhiteSpace().
- first line replaces a line that starts and ends with white spaces
- second line replaces a single white space that is alone on a line.
- third line replaces the end of a line that finishes with trailing spaces
- same as 3 but for the single white space case