2016-08-24 52 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

相關問題