I’m trying to create an autocmd that will replace all the whitespaces in the file when I exit the insert mode. However, AFAIK that would make Vim remember the pattern and remove what was already in there.
" Add function for remove tailing whitespaces
command! CleanupTrailingSpaces :%s/\s\+$//ge | :nohlsearch
autocmd InsertLeave * :CleanupTrailingSpaces
Is there a flag for :s[ubstitute] that will make it not saving the pattern?
Such a flag would be useful, but does not yet exist. However, you can save and reset the register like this: