匹配 foo 或 bar vim 正则表达式 [英] Match foo or bar vim regex
本文介绍了匹配 foo 或 bar vim 正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有一种在 vim
搜索和替换中一次匹配多个单词的方法?类似的东西:
Is there a method of matching multiple words at once in a vim
search-and-replace? Something like:
:%s/foo|bar//g
搜索 foo
或 bar
并用空替换(这搜索模式 foo|bar
,这不是我想要的想).我可以这样搜索多个字符:
to search for foo
or bar
and replace with nothing (this searches for the pattern foo|bar
, which isn't what I want). I can search for multiple characters this way:
abcdef
:%s/[ace]//g
结果:
bdf
我可以用文字做同样的事情吗?
Can I do the same thing with words?
我很清楚我可以这样做:
I'm well aware I could do this like this:
:%s/foo//g
:%s/bar//g
如果存在这样的事情,我正在寻找一种单行解决方案.
I'm looking for a one-line solution, if such a thing exists.
推荐答案
在 vim 正则表达式中,交替操作符需要用反斜杠转义:使用 foo\|bar
.
In vim regexes, the alternation operator needs to be escaped with a backslash: use foo\|bar
.
这篇关于匹配 foo 或 bar vim 正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文