Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a flag for :s[ubstitute] in Vim that will not save the pattern?

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?

like image 449
sikachu Avatar asked Aug 20 '12 16:08

sikachu


1 Answers

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
like image 66
Conner Avatar answered Nov 15 '22 10:11

Conner