2016-08-24 51 views
3

目前的内容我有这个脚本在当前项目中搜索词下光标:Vim的<C-R><C-W>忽略该行

nnoremap <leader>K :grep! "\b<C-R><C-W>\b"<CR>:cw<CR> 

它的工作原理时,这个词用b开始,除了就好了。

这是由于<C-R><C-W>只完成其余的字。例如,如果我在寻找“分支”,我的模式得到这样的事情:

\branch\b 

即相当于搜索作品“牧场”。

有关如何解决这个问题的想法?

+1

你可以用'-w'选项告诉'grep'只搜索单词..这样你不需要使用'\ b',如果你只想匹配'-b'选项整行 – Sundeep

回答

1

试试这个:nnoremap <leader>K :execute 'grep! "\b"'.expand("<cword>").'"\b"'<CR>:cw<CR>

<cword>将扩大到当前光标下的单词,如:help :<cword>解释说,与人相处:

<cword> is replaced with the word under the cursor (like |star|) 
<cWORD> is replaced with the WORD under the cursor (see |WORD|) 
<cfile> is replaced with the path name under the cursor (like what|gf| uses) 

Check the help for more info

+1

这一个为我工作,我只需要做一个变化:'nnoremap K:执行'grep! “\ b”'。expand(“”)。'“\ b”':cw ' –

+0

哦,是的,我的坏。我有点急,只用':echo'进行测试。我将编辑以包含您的线路。 – rgoliveira

相关问题