如何在vim中搜索整个单词有几个答案。例如,此链接How to do whole-word search similar to "grep -w" in Vim会回答它。
我想知道vim中有\<word\>
可以替代搜索整个单词吗?我问的原因是出于好奇。我想知道vim的另一种选择。我知道其他一些工具,例如grep
可以执行相同的任务,但我有兴趣在vim
找到方法。
编辑:\<\>
出了什么问题?我在问另类。如果没有,请将其放在答案而不是评论中。请再次阅读标题。请不要无缘无故地回避问题,也不要关闭合理的问题。
答案 0 :(得分:0)
Technically yes, you can place your cursor over that word in the document and press * which will automatically populate the search with the word surrounded by word boundaries. Same with # for searching backwards.
Also, Vim's default search escaping is quite verbose and poorly designed. I highly recommend starting all searches with the "very magic" switch, \v
, so that you don't have to escape special characters. As in you can type /\v<word>
and the <
and >
will be treated correctly as word boundaries without having to escape them.
A mapping to "enable" very magic for all searches:
nnoremap / /\v
nnoremap ? ?\v