I'm trying to use
git grep as my
grepprg, but I keep getting spurious files such as
~/fatal: Not a git repository (or any of the parent directories): .git. Is there a way to configure vim to correctly ignore diagnostic messages? I'm okay with general solutions for configuring
grepprg and related options or solutions specific to
git grep. However, I'd prefer a vim-only solution that doesn't involve writing wrapper programs around
Here's a snippet from my
:browse oldfiles showing the spurious file.
1: ~/.vimrc.bak 2: ~/.vimrc 3: ~/.bash_aliases 4: ~/.bashrc 5: /tmp/eee 6: /tmp/.vimrc 7: /tmp/.vimr 8: ~/fatal: Not a git repository (or any of the parent directories): .git
This problem is reproducible using the following vimrc.
set grepprg=git\ --no-pager\ grep\ --no-color\ -n\ $* set grepformat=%f:%l:%m,%m\ %f\ match%ts,%f
The above vimrc is based on this answer.
The first thing I tried is
set shellredir=>, but the behavior of the grep
builtin command does not appear to change according to the value of
I've confirmed experimentally that
shellredir has no effect on the
grep command. I can confirm that
set shellredir="00000000" doesn't appear to affect the
grep ex command.
ex_make is used for
make, and other commands that populate the
quickfix list. Briefly looking at the code, though, I can't tell why stderr is always captured on Linux and also can't say definitively that
shellredir isn't used at all.
One semi-solution that does work is using a wrapper around git grep that immediately discards stderr before
vim can see it.
#!/usr/bin/perl # ~/bin/gitgrep open(STDERR, ">/dev/null"); exec("git", "--no-pager", "grep", "--no-color", "-n", @ARGV);
and the corresponding vimrc
set grepprg=$HOME/bin/gitgrep\ $* set grepformat=%f:%l:%m,%m\ %f\ match%ts,%f