How do I search for the exact text I have selected?
Answer
y/\V<C-r>"<CR>
Explanation
By yanking a visual selection and pasting it into the search prompt with \V (very nomagic), you can search for exact text including special characters.
How it works
- Select text in visual mode
yyanks the selection/\Vstarts a literal search<C-r>"pastes the default register into the search prompt<CR>executes the search
Example
To search for the exact text obj.method(x) which contains regex special characters, select it visually, then y/\V<C-r>"<CR>.
Tips
\Vprevents.and()from being interpreted as regex<C-r>followed by a register name pastes it into the command line- This is useful for text that contains regex metacharacters
- Some users create a mapping for this common operation