0

This question is inspired by Getting 'git grep' to work effectively in VIM.

My .vim/vimrc entries are similar to those in the question:

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

The Ggr command works. Unfortunately Ctrl-F produces a nasty error:

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

How can I properly define this nnoremap in my .vim/vimrc file?

davidvandebunte
  • 1,286
  • 18
  • 25

1 Answers1

2

<cword>works with expand, try

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