One way to make sure to remove all trailing whitespace in a file is to set an autocmd in your .vimrc file. Every time the user issues a :w command, Vim will automatically remove all trailing whitespace before saving.
autocmd BufWritePre * :%s/\s\+$//e
Remove unwanted spaces - Vim Tips Wiki http://vim.wikia.com/wiki/Remove_unwanted_spaces