regex - 是否有 :s[ubstitute] in Vim that will not save the pattern? 的标志

标签 regex vim substitution

我正在尝试创建一个 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/

相关文章:

vim - 在 vim 中,如何用空格替换正则表达式模式?

正则表达式替换 : only replace the first occurance from a "or" condition

ruby 正则表达式替换方程式

java - 正则表达式查找复杂括号外的特定字符串

javascript从字符串中提取数字不起作用

javascript - 排除正则表达式模式中仅由制表符组成的空格

git - git 中的 vimdiff 和 vimdiff2 有什么区别?

vim - 新马特 : How to Edit To/Subject/CC Fields in Vim?

regex - 如何在 Google 表格中删除文本并切换逗号和句号的位置

python - 如何删除或替换两个模式之间的多行文本