nnoremap命令与vim逃逸

时间:2018-07-16 00:45:20

标签: git vim vim-fugitive

这个问题的灵感来自Getting 'git grep' to work effectively in VIM

我的.vim/vimrc条目与问题中的条目相似:

command -nargs=1 Ggr execute 'silent Git! grep -Win --heading' <q-args>
nnoremap <C-F> :Ggr <cword><CR>

Ggr命令有效。不幸的是,Ctrl-F会产生讨厌的错误:

Error detected while processing function <SNR>33_Git[2].. <SNR>33_Edit[53]..<SNR>33_Edit[36]..<SNR>33_ExecuteInTree:
line    5:
E348: No string under cursor
Error detected while processing function <SNR>33_Git[2]..<SNR>33_Edit[53]..<SNR>33_Edit:
line   36:
E171: Missing :endif
Error detected while processing function <SNR>33_Git[2]..<SNR>33_Edit:
line   53:
E171: Missing :endif
Error detected while processing function <SNR>33_Git:
line    2:
E171: Missing :endif

如何在我的nnoremap文件中正确定义此.vim/vimrc

1 个答案:

答案 0 :(得分:2)

<cword>expand一起使用,请尝试

command -nargs=1 Ggr execute 'silent Git! grep -Win --heading' <q-args>
nnoremap <C-F> :execute 'Ggr '.expand('<cword>')<cr>