From http://vim.wikia.com/wiki/Remove_unwanted_spacesfunction TrimWhiteSpace()  %s/\s\+$//eendfunctionautocmd FileWritePre * call TrimWhiteSpace()autocmd FileAppendPre * call TrimWhiteSpace()autocmd FilterWritePre * call TrimWhiteSpace()autocmd BufWritePre * call TrimWhiteSpace()On :write the cursor moves to the first non-blank character of the last trimmed line. How can I make it stay in place?
Removing trailing spaces with the substitute command changes the cursor position
cursor movement;substitute;whitespace