Windows gvim - use unix grep

2

Using Windows 10. I have gvim installed. I also have git, and I have git's bin in my PATH (C:\program files (x86)\Git\bin), which puts git's gnu grep in my path so I can use it in the command shell.

> grep -V
grep (GNU grep) 2.4.2 

However, when I use grep from vim -

:grep -ir 'something' .

It is using FINDSTR in windows, which doesn't work very well.

How do I make gvim use the GNU grep? I tried pre-pending the git bin dir to my vim path but that didn't help.

user39160

Posted 2016-01-13T23:17:47.620

Reputation: 185

Have you tried the grep.vim : Grep search tools integration with Vim plugin?

– DavidPostill – 2016-01-13T23:25:33.040

thanks for pointing that out. that may be the answer, but I'd like to just try getting the grep command use gnu grep rather than an uppercase Grep command. – user39160 – 2016-01-13T23:37:26.420

You could always install Cygwin ;) – DavidPostill – 2016-01-13T23:42:56.773

1Did you read :help grepprg? – romainl – 2016-01-14T12:49:35.110

@romainl - wow I'll have to set aside half a day to do that ;) one of the longest docs I've seen. Looks like it's probably the answer though – user39160 – 2016-01-14T15:27:14.107

Answers

1

The external executable for :grep is controlled by the 'grepprg' option, and on Windows, this defaults to findstr, as :help 'grepprg' details:

For Win32, the default is "findstr /n" if "findstr.exe" can be found, otherwise it's "grep -n".

So, just put the following into your ~/.vimrc:

set grepprg=grep\ -nH

Ingo Karkat

Posted 2016-01-13T23:17:47.620

Reputation: 19 513

thanks! what's the backslash for? – user39160 – 2016-01-15T18:08:07.227

1The backslash escapes the space character; this is necessary for :set. – Ingo Karkat – 2016-01-18T07:30:17.123