开发者

How to make vimgrep do word match search?

I have below statement in _vimrc file to map F3 to do vimgrep for word under current cursor.

map <F3> :execute "noautocmd vimgrep /" . expand("<cword>") . "/gj **/*." .  expand("%:e") <开发者_如何学CBar> cw<CR>

Now, I want to make it vimgrep for exact word match for word under current cursor. I changed it as below but it doesn't work.

map <leader>s :execute "noautocmd vimgrep /\<" . expand("<cword>") . "\>/gj **/*." .  expand("%:e") <Bar> cw<CR>

Anything is wrong? How can i achieve exact word match?


The problem is that you need to double up the backslashes - a single backslash will escape the next character, and if the character does not have a special meaning then the backslash is removed. e.g.

echo "\<"

will print

<

This seems to work OK:

map <leader>s :execute "noautocmd vimgrep /\\<" . expand("<cword>") . "\\>/gj **/*." .  expand("%:e") <Bar> cw<CR>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜