If any of the globs has no match, in zsh, the command will be aborted. This means you need to escape your globs.
I suggest you use shellescape() to build your 'grepprg' command.
let &grepprg='grep -n -R --exclude=' . shellescape(&wildignore) . ' $*'
For more help see:
:h 'grepprg' :h shellescape() man zshexpn
Alternatives to grep
Have you thought about using a different program for 'grepprg' like ag, the silver searcher, git grep, ack, or ripgrep?
Ag, The Silver Searcher
Ag by default ignores the following files:
- Ignores binary files e.g.
*.o and *.pyc - Ignores version control directories e.g.
.git, .hg, and .svn - Will ignore files that matched your
.gitignore files. I imagine your tags and cscope file will be ignored by this - Uses PRCE regular expressions
This completely or nearly completely eliminates your excludes.
set grepprg=ag\ --vimgrep\ $* set grepformat=%f:%l:%c:%m
If vanilla grep settings aren't your thing then you can use Ack.vim which works with ag despite its name.
Using Ripgrep:
Ripgrep is similar to Ag, the silver searcher.
- Ignores binary files e.g.
*.o and *.pyc - Ignores version control directories e.g.
.git, .hg, and .svn - Will ignore files that matched your
.gitignore files. I imagine your tags and cscope file will be ignored by this - Uses Rust's regular expressions
- Super fast! Ripgrep is faster than {grep, ag, git grep, ucg, pt, sift}
Setting for you vimrc:
set grepprg=rg\ --vimgrep set grepformat=%f:%l:%c:%m
Using git grep or :Ggrep
If you are using git and fugitive.vim's :Ggrep which uses git grep. git grep can be a wonderful option because it will by default only search inside of tracked files. Therefore sidestepping the need to add ignores.
Using git grep without fugitive.vim:
set grepprg=git\ --no-pager\ grep\ --no-color\ -n\ $* set grepformat=%f:%l:%m,%m\ %f\ match%ts,%f
Note: this uses the current working directory as a starting point
Using ack
Ack is a tool like grep, optimized for programmers. Ack is a perl script that can be easier to install on locked down system. It is the forerunner to both Ag and Ripgrep.
- Ignore version control directories by default
- Ignore backup files and core dumps by default
- Can use
ackrc file to ignore more files by default - Ack 1.* series ignores binary files by default. 2.* does not.
- Uses Perl's regular expressions
- Often faster than normal grep because it searches less files by default
:grep settings:
set grepprg=ack\ -s\ -H\ --nopager\ --nocolor\ --nogroup\ --column set grepformat=%f:%l:%c:%m,%f:%l:%m
If vanilla grep settings aren't your thing then you can use Ack.vim.