我正在尝试创建一个 autocmd
当我退出插入模式时,它将替换文件中的所有空格。然而,AFAIK 会让 Vim 记住模式并删除已经存在的内容。
" Add function for remove tailing whitespaces
command! CleanupTrailingSpaces :%s/\s\+$//ge | :nohlsearch
autocmd InsertLeave * :CleanupTrailingSpaces
是否有
:s[ubstitute]
的标志这将使它不保存模式?
最佳答案
这样的标志很有用,但尚不存在。但是,您可以像这样保存和重置寄存器:
" Add function for remove tailing whitespaces
command! CleanupTrailingSpaces let reset = @/ | %s/\s\+$//ge | let @/ = reset | nohlsearch
autocmd InsertLeave * :CleanupTrailingSpaces
关于regex - 是否有 :s[ubstitute] in Vim that will not save the pattern? 的标志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12041302/