How do I search for a pattern across all files in my project without leaving Vim?
Answer
:vimgrep /pattern/ **
Explanation
:vimgrep /pattern/ ** searches recursively through all files in the current working directory tree using Vim's own regex engine, populating the quickfix list with every match. It requires no external tools and understands the same patterns you use in / searches — making it a powerful built-in alternative to :grep.
How it works
:vimgrepruns Vim's internal grep across one or more files/pattern/uses Vim regex (supports\v,\c,\<word\>, etc.)**is the glob for "all files, recursively" — Vim expands this from the current directory- Results land in the quickfix list, navigable with
:cn(next),:cp(prev),:copen(show list)
Example
Find every TODO comment across all files in your project:
:vimgrep /TODO/ **
:copen
The quickfix window shows each match with file, line, and content. Press <CR> to jump to any entry.
Filter by file type to avoid searching binaries:
:vimgrep /\<apiKey\>/ **/*.go
Tips
- Add
gflag to collect all matches per line, not just the first::vimgrep /pat/g ** lvimgrepsends results to the location list (window-local) instead of the shared quickfix list — useful when you have multiple searches open simultaneously- After populating the quickfix list, use
:cdo s/old/new/gcto interactively apply changes across every match in the project - For very large projects,
:grepbacked byripgrep(:set grepprg=rg\ --vimgrep) is faster, but:vimgrepneeds no configuration and works everywhere