Sometimes you want to search for a long string in Vim. When using a GUI interface you may be able to get away with CTRL+c, CTRL+v but when you are in a terminal, it is a little trickier to use Vim Visual Mode search for a selection. Here is how to search in Vim using Visual Mode to select the search string.
- Select the text in visual mode (
vand move cursor to highlight)
- Yank the text (
- Go into search mode (
- Select registers (
- Select the unnamed register, i.e. the last yank or delete (
You never use visual mode?
Then you aren’t leveraging all the power of Vim. To be fair, I don’t think I know anyone leveraging all the power of Vim but visual mode is a great tool to add to your utility belt.
Using the * Command
Before jumping into Visual Mode (with
v), you may be able to do your search without entering Visual Mode. When press
Shift + 8) in Normal mode, Vim will search for the word (i.e.
keyword) under the cursor. Assuming the text you want to search is a single word, this is a great way to search.