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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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

Your Answer


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.