Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I looking more for a method that is "built-in" to vi, and not something that I could do in my .vimrc. Though, solutions for .vimrc are appreciated. :-)

When I want to search a string, sometimes that string is already typed in and I want to see if it's being used elsewhere on the document. For example: I see a variable, but I want to know where it was initialized, so I'll search that variable's name and keep clicking n or SHIFT+n til I find it.

int c = 0;
.
. //100s or 1000s of lines of code
.
c = 5;

Is there a shortcut way to search the string that my cursor is hovered over? Not the mouse cursor, but the vi cursor (if that makes sense).

share|improve this question
add comment

1 Answer

In vim just press * to search forward ... # will search backwards.

Oh: prepend * and # with g to also match partial words.

share|improve this answer
    
You've got it all mixed up. * for forward, # for backward, g*/g# for not whole words. n/N to repeat search in the same/reverse direction. –  Stephane Chazelas Apr 19 '13 at 22:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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