How do I access and reuse the last search pattern?
Answer
"/ register
Explanation
The / register contains the most recent search pattern. You can reference it in substitutions, macros, or paste it into the buffer.
How it works
"/stores the last search pattern<C-r>/in insert mode inserts the pattern:s//replacement/reuses it (empty search = last pattern)@/evaluates it as a command (rarely useful)
Example
After searching /function, the / register contains function. You can use it in:
:%s//method/g " Replaces using last search pattern
Tips
- This is why
:%s//new/gworks after a search :let @/ = 'pattern'sets the search pattern programmatically:let @/ = ''clears the current search highlighting- The register updates with every
/,?,*,#search