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:
" Add function for remove tailing whitespaces
command! CleanupTrailingSpaces let reset = @/ | %s/\s\+$//ge | let @/ = reset | nohlsearch
autocmd InsertLeave * :CleanupTrailingSpaces
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With