How do I search with vimgrep only in specific file types?
Answer
:vimgrep /pattern/ **/*.py
Explanation
By specifying a file glob pattern with :vimgrep, you can restrict the search to specific file types. The ** pattern makes it recursive.
How it works
**/*.pymatches all Python files recursively**/*.{js,ts}matches JavaScript and TypeScript files- Results populate the quickfix list
Example
:vimgrep /class.*Model/ **/*.py
:copen
Searches for class definitions with "Model" in all Python files.
Tips
:vimgrep /pattern/g filereports every match, not just first per line:vimgrep /pattern/j filedoes not jump to the first match:grep -r --include='*.py' pattern .uses external grep (faster):set grepprg=rg\ --vimgrepmakes:grepuse ripgrep- Use
:copento see all results in the quickfix window