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


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

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

  • 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. – Stéphane Chazelas Apr 19 '13 at 22:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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