Answer
:let @/ = '\V' . escape(@0, '\')
Explanation
When the text you yank contains regex characters, a normal / search can produce noisy or surprising matches. A faster approach is to load the last yank directly into the search register and force literal matching. This gives you an exact, repeatable search target without manual escaping in the command line.
How it works
@0is the yank register that stores the most recent yank operation@/is the search register, which controls whatnandNrepeat\Vswitches the pattern to very nomagic, so almost every character is treated literallyescape(@0, '\\')preserves existing backslashes safely inside the pattern
After running the command once, press n to jump forward through exact matches and N to go backward.
Example
Suppose you yanked this token from a config file:
api.v2/users[active]
Run:
:let @/ = '\V' . escape(@0, '\\')Now n finds only literal api.v2/users[active] occurrences, instead of treating ., [, and ] as regex operators.
Tips
- This is excellent for logs, URLs, and code symbols with punctuation.
- If your yank includes newlines, Vim still stores it in
@0; inspect with:register 0when debugging. - Pair with
:set hlsearchso you can visually confirm the exact literal pattern loaded into@/.
category: registers tags: #registers #search #regex #command-line
Next
How do I make buffer jumps prefer the last-used window that already shows the target buffer?
Related Tricks
How do I paste the unnamed register after transforming it to uppercase?
:put =toupper(@")
How do I paste multiline clipboard text as a comma-separated list in Insert mode?
<C-r>=substitute(getreg('+'), '\n\+', ', ', 'g')<CR>
How do I insert a register in Insert mode without reindenting each inserted line?
<C-r><C-o>a
How do I insert a timestamp computed by Vimscript directly from Normal mode?
"=strftime('%Y-%m-%d %H:%M')<CR>p
How do I copy my most recent yank from register 0 into the system clipboard register?
:let @+ = @0
