How do I search for yanked text literally in Vim without escaping regex characters?
Answer
/\V<C-r><C-r>"
Explanation
When your yanked text includes regex symbols like ., *, ?, or [], a normal / search can behave unpredictably because Vim treats those as pattern operators. A reliable way around this is to start a very nomagic search and insert the register literally from the command line. This keeps the pattern exact and avoids manual escaping every special character.
How it works
/enters forward search mode\Vswitches to very nomagic mode, so almost everything is treated as literal text<C-r><C-r>"inserts the unnamed register literally on the command line- Press
<CR>to execute the search
The <C-r><C-r> form is important: it inserts text in a way that avoids extra command-line escaping behavior, which makes this workflow dependable for symbols-heavy snippets.
Example
Suppose you yanked this string:
api/v1/users[0].email?active=true
A plain search like /api/v1/users[0].email?active=true may misinterpret several characters as regex operators.
Use this instead:
/\V<C-r><C-r>"
Then press <CR>. Vim searches for the exact literal string.
Tips
- Works best right after a yank, since the unnamed register already contains your target text
- If needed, use a named register by replacing
"witha,b, etc. - Combine with
nandNto move through exact literal matches quickly