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 :help did not... huh... help me.

link|improve this question

67% accept rate
feedback

4 Answers

up vote 3 down vote accepted

I never felt the need for such a feature but, considering you can find a need for any feature on Vim, I think that should help:

Search for visually selected text

I didn't test it but, looking at the code, it seems to be exactly what you're searching for.

link|improve this answer
Since both of you posted the exact same answer, I'm accepting your answer because you need more reputation than akf, and because your answer has more votes. Nevertheless, I would like to thank both of you for your answers. – Denilson Sá Sep 15 '09 at 9:59
feedback

You can find a method to create this behavior here at the vim wiki.

link|improve this answer
feedback

You can yank the hightlighted text first. Then

  • /

  • Ctrlr

  • "

Which will paste what you have yanked after the /.

link|improve this answer
Nice idea... except that the pasted text will be interpreted as a regex, which is not desired. :-( – Denilson Sá Aug 22 '10 at 16:58
feedback

In my configurations on two separate machines, if I select text and then hit / it automatically searches for the selected text.

link|improve this answer
That's not the default behavior. Here, when I press / (while in visual mode), it just shows an empty regex prompt, waiting for me to type something. – Denilson Sá Sep 21 '09 at 10:51
Odd, because I never did anything to enable it. – Nathan Fellman Sep 21 '09 at 11:25
Many distros ship a non-standard vim config as the default (probably because the standard vim config disables many useful features, mostly for vi compatibility). – sleske Mar 23 '10 at 10:08
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.