开发者

How to make vimgrep do word match search?

开发者 https://www.devze.com 2022-12-13 13:28 出处:网络
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\

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

精彩评论

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

关注公众号