How do I search for a pattern across multiple files?
Answer
:vimgrep /pattern/ **/*.ext
Explanation
The :vimgrep command searches for a pattern across multiple files and populates the quickfix list with the results. It uses Vim's internal regex engine.
How it works
:vimgrep /pattern/ filessearches the given files**/*.extis a glob for all matching files recursively- Results go into the quickfix list
:copenopens the quickfix window to browse results
Example
:vimgrep /TODO/ **/*.py
:copen
This finds all TODO comments in Python files and opens the quickfix list.
Tips
:cnext/:cprevnavigate between matches:vimgrep /pattern/g filelists every match (not just one per line):grepuses the external grep command instead (faster for large projects):lvimgrepuses the location list instead of quickfix