如何进行类似于“grep -w”的全文搜索在Vim [英] How to do whole-word search similar to "grep -w" in Vim
本文介绍了如何进行类似于“grep -w”的全文搜索在Vim的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何在Vim中进行像 grep -w
这样的全文搜索,它只返回找到的字符串是整个单词的行,而不是一个更大的单词?
grep -w
:只选择包含形成整个单词的匹配的行。
这可以在Vim中完成吗?
解决方案
\< bar\>
匹配 bar
但既不 foobar
也不是 barbaz
也不是 foobarbaz
。
在替换中像这样使用它:
:s / \< bar \> / baz
使用它可以列出包含整个单词的所有行, bar
:
:g / \< bar\>
:h pattern
是一个很好的阅读。
How do I do a whole-word search like grep -w
in Vim, which returns only lines where the sought-for string is a whole word and not part of a larger word?
grep -w
: Select only those lines containing matches that form whole words.
Can this be done in Vim?
解决方案
\<bar\>
matches bar
but neither foobar
nor barbaz
nor foobarbaz
.
Use it like this in a substitution:
:s/\<bar\>/baz
Use it like this to list all the lines containing the whole word bar
:
:g/\<bar\>
:h pattern
is a good read.
这篇关于如何进行类似于“grep -w”的全文搜索在Vim的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文