How to search for selected text in Vim?
Problem
I'm aware that I can use / followed by a regex to search something. And I can use ? to search backwards. And I can use n and N to repeat the search forward and backward. There are also two nice shortcuts: * or # will search for the word under the cursor (forward/backward). That's very useful! (there are also g* and g# variants) But... Once I've selected text using visual mode (v), how can I ask Vim to search for exactly that text? A quick look at did not... huh... help me.
Error Output
:help
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Fix for: How to search for selected text in Vim?
The following sequence will do what you want, given an already selected block of text: y (yank the selected text, into the register by default) / (enter search mode) (\ V) (optional, enter "very no magic" mode*) Ctrl+r " (insert text from register) Enter (Engage!) (*) "very no magic" mode interprets the following text as plain text instead of as a regex. note however that and are still special and will have to be handled in other ways. If the text does not have any characters considered special…
Awaiting Verification
Be the first to verify this fix
Sign in to verify this fix