How do I run vimgrep across a project using whatever pattern is currently in the search register?
Answer
:execute 'vimgrep /' . @/ . '/gj **/*'
Explanation
If you already refined a search interactively with / or ?, retyping that pattern for project-wide grep is repetitive and error-prone. This command reuses the current search register (@/) and injects it directly into :vimgrep, so your global search stays aligned with what you just validated in-buffer. It is a fast bridge from local exploration to project-wide impact analysis.
How it works
@/holds the last search pattern exactly as Vim is using it:execute ...builds an Ex command string dynamically'vimgrep /' . @/ . '/gj **/*'becomes a full:vimgrepcallgcaptures all matches per file;javoids jumping to the first match during list construction- Results land in quickfix, ready for
:copen,:cnext,:cdo, and related workflows
This is especially powerful when your search pattern is complex (word boundaries, groups, lookarounds) and you do not want to manually escape it again.
Example
First, refine a pattern in the current buffer:
/\<FeatureFlag\>\s*:\s*true
Then project-wide:
:execute 'vimgrep /' . @/ . '/gj **/*'
:copen
Now quickfix contains every matching occurrence across the project tree.
Tips
- Run
:set noignorecaseor pattern flags before building@/if case behavior matters - Scope files tighter than
**/*when possible (for example**/*.ts) for speed - Pair with
:cdofor repeatable fix-ups once matches are confirmed