我想定义一个自定义命令来执行以下步骤:grep 当前单词,copen,增量搜索 grep 单词。这是我正在使用的命令:
nmap <C-p> :execute "grep! -Irn " . shellescape(expand("<cword>")) . " ."<cr>:copen<cr>:g/<cword>/<cr>
但是在打开 quickfix 窗口后,第二个 cword 会扩展为当前单词。如何使用 grep 之前使用的单词?
我想定义一个自定义命令来执行以下步骤:grep 当前单词,copen,增量搜索 grep 单词。这是我正在使用的命令:
nmap <C-p> :execute "grep! -Irn " . shellescape(expand("<cword>")) . " ."<cr>:copen<cr>:g/<cword>/<cr>
但是在打开 quickfix 窗口后,第二个 cword 会扩展为当前单词。如何使用 grep 之前使用的单词?
与您<cword>
进入的方式相同grep
:
nmap <C-p> :execute "grep! -Irn " . shellescape(expand("<cword>")) . " .\<cr>:copen\<cr>:g/" . expand("<cword>"). "/\<cr>"<cr>
一些想法:
:g
. 例如:let @/ = "foo"
nnoremap
escape()
使其更具弹性。看:h escape(
:vimgrep
. 看:h :vimg