Your .vimrc file is typically located in your home directory. So you can edit it by typing:
Then adding the following line to your .vimrc will ensure that every time you save a file (:w), it will remove all trailing whitespace.
autocmd BufWritePre * :%s/\s\+$//e
Trailing whitespace will now be removed from the file when using the Vim editor.