12

Does anyone know syntax of Vimgrep to search with multiple file globs? I am trying to use this command to search in the current directory.

map <F3> :execute "vimgrep /" . expand("<cword>") . "/j **/*.c* *.txt" <Bar> cw<CR>

With using this command, Vim searches only for *.c*. Any idea about how to search for multiple filetypes?

Keith Pinson
  • 7,835
  • 7
  • 61
  • 104

3 Answers3

25

To search for "text" in all *.txt & *.php files recursively from current directory.

:vimgrep "text" **/*.txt **/*.php
Naga Kiran
  • 8,585
  • 5
  • 43
  • 53
4

in this directory

:vimgrep "search subject" *.c
:vimgrep blah *.[ch]
:vimgrep blah *.c* *.h

in this or any descendant directory

:vimgrep "search subject" ./**/*.c
Adrian Panasiuk
  • 7,249
  • 5
  • 33
  • 54
0

I am just getting into Vim and this question taught me about the existence of vimgrep. Is there a way to loop through the results? So say I wanted to find all of the instances of "user", and I use

:vimgrep /user/g **/*.rb

How could I loops through the instances of that text?

Scott Radcliff
  • 1,501
  • 1
  • 9
  • 13