I try to use vim's internal grep with '**'
wildcard as in the following command:
grep "test" **\*.txt
vim gives the following error:
FINDSTR: Cannot open **\*.txt
When I remove the '**'
wildcard, the command works properly:
grep "test" *.txt
I changed the backslashes to forward slashes, but it didn't help neither:
grep "test" **\*.txt
This gives the above error again.
What might be the reason?
Note: I use GVim 7.2 on Microsoft Windows XP.
Doing a ":grep" in Vim under XP does not use "grep.exe" by default. By default "FINDSTR" is used which is part of the Windows installation. "FINDSTR" is not compatible to grep. Due to this you get the error message
FINDSTR: Cannot open **\*.txt
See ":help grepprg".
If you want to use a Windows port of grep you have to install it since grep is neither part of Windows nor of the Vim installation.
But since 7.0 Vim has an internal grep called vimgrep. See ":help vimgrep" for details.
You have to set 'grepprg' accordingly so that either grep or vimgrep is used (instead of the default FINDSTR).
On Windows, if you want to hook into the faster findstr
you can use
set grepprg=findstr\ /n\ /s
In your .vimrc and now
:vimgrep methodname **/*.py
is equivalent to
:grep methodname *.py
Both return a list of results you can navigate through the quickfix window (:copen
, :cn
/:cp
, :cclose
)
In my experience findstr is about 30 times faster than vimgrep, however it might not matter with your project size and vimgrep
's regex are far nicer to use.
Install cygwin, mingw, or unxutils to get grep (I use cygwin). Add the bin directory to your PATH.
And like Habi said, add to your vimrc:
set grepprg=grep\ -nH
(This is what grep on *nix uses by default.)
Also, if you :help grep
, you'll get a description of the differences between grep and vimgrep. (Speed vs. portability and flexibility.)
You should try vimgrep
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With