sik*_*chu 5 regex vim substitution
我正在尝试创建一个autocmd将在我退出插入模式时替换文件中的所有空格.然而,AFAIK会让Vim记住这个模式并删除已经存在的模式.
" Add function for remove tailing whitespaces
command! CleanupTrailingSpaces :%s/\s\+$//ge | :nohlsearch
autocmd InsertLeave * :CleanupTrailingSpaces
Run Code Online (Sandbox Code Playgroud)
是否有一个标志:s[ubstitute]会使它不能保存模式?
这样的标志会很有用,但还不存在.但是,您可以像这样保存和重置寄存器:
" Add function for remove tailing whitespaces
command! CleanupTrailingSpaces let reset = @/ | %s/\s\+$//ge | let @/ = reset | nohlsearch
autocmd InsertLeave * :CleanupTrailingSpaces
Run Code Online (Sandbox Code Playgroud)