Search for selection in Vim

Viewed 26386

I use Vim and Vim plugins for Visual Studio when writing C++. Often, I find myself wanting to search for a string within a function, for example every call to object->public_member.memberfunc().

I know Vim offers a convenient way to search for a single word, by pressing * and #, and it can also search for typed strings using the ubiquitous slash / command. When trying to search for all the instances of a longer string like the one above, it takes a while to re-type after /.

Is there a way to search for the selection? For example, highlight with v, then copy with y, is there a way to paste after /? Is there an easier shortcut?

5 Answers

Check this Vim tip: Search for visually selected text

Or you can simply yank the selected text with y and go to search mode /, then you can paste the last yanked text with Ctrl+R 0

Use q / instead of just /. (Same with q :). Now you can VIM-edit through your command and search history! (Try Ctrl-N and Ctrl-P sometime).

Related