Search through set of files designated by multiple globs with Vimgrep
Asked Answered
F

3

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?

Flatting answered 23/6, 2009 at 18:31 Comment(0)
N
25

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

:vimgrep "text" **/*.txt **/*.php
Navarro answered 1/7, 2009 at 19:21 Comment(3)
I would also add, that typing :cn and :cp to go to the next and previous matches respectively.Diocesan
This will get annoying confirming infos when one of the given types doesn't exit.Eth
"**/*.php" [new directory]·\n"[Quickfix list]...\n Press Enter to continue" Eth
U
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
Unbuild answered 23/6, 2009 at 18:34 Comment(1)
It's worth noting that you don't need the ./ for it to work recursively in the current dir.Victorinavictorine
S
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?

Scalp answered 14/11, 2010 at 17:17 Comment(2)
These results get added to the quicklist window. You can open the quicklist window with ":copen" and can loop through the resultsNavarro
Umm, khebbie, this was over a year ago? Thanks for the feedback.Scalp

© 2022 - 2024 — McMap. All rights reserved.