带有 vim-fugitive 的 nnoremap 命令

nnoremap command with 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

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

<cword>expand 一起使用,尝试

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