views:

1531

answers:

2

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 selection? For example, highlight with v, then copy with y, is there a way to paste after / ? Is there an easier shortcut?

+21  A: 

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

CMS
Very cool. CMS = fast + detailed.
Marcin
@CMS. Thanks. Great tip! Using :reg to see what's in your registers and then using cntl-R N to get what's in register N is excellent!
Rob Wells
CMS
you are now officially my hero.
alesplin
+6  A: 

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).