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*trueThen project-wide:
:execute 'vimgrep /' . @/ . '/gj **/*':copenNow 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
category: search tags: #search #vimgrep #quickfix #registers #workflow
Next
How do I join a wrapped paragraph into one line without manual cursor moves?
Related Tricks
How do I search non-greedily across multiple lines between two markers?
/\vstart\_.{-}end
How do I search only the message part of TODO comments using match boundaries?
/\vTODO:\s*\zs.{-}\ze\s*($|#)
How do I search for 'bar' that is not preceded by 'foo'?
/foo\@<!bar
How do I restrict a search to a specific line-number window without selecting text first?
/\%>20l\%<40lTODO
How do I populate a window-local location list from the current file and open it immediately?
:lgrep /pattern/ % | lopen
