Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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

After I search for "foo" by doing "?foo", I can search forward by "n" or backward by "N", however sometimes the n/N directions are flipped in the middle of search. If I restart Vim, it's OK again. What key sequence may I have pressed to cause this? How to revert back to normal mode?

I don't recall that I ever ran into this in old Vi.

EDIT: it's not the Caps Lock key. Thanks for the suggestion though.

share|improve this question
I guess it's not just the wrapping around at the end/beginning of the file? Or maybe you typed * or something that reverses the search? I know I unintentionally do it a lot of time. – Dave Vogt Aug 9 '10 at 16:07
@Dave Vogt, it's not just end/beginning of the file. I just tested "", you are right, if I press "" I can change/correct the search direction. If you put in an answer, I will vote it up and accept it. Thanks. – grokus Aug 9 '10 at 16:15
up vote 7 down vote accepted

This can happen if you started out searching backwards with ?foobar, and you pressed / in the middle. Now you're searching forward, so n and N are switched relative to what you used to have. The same thing will happen if you started with / and pressed ? in the middle.

share|improve this answer
Sir you are right. I just tested what you said. Could you tell me what role "*" is playing in this midst? – grokus Aug 9 '10 at 17:47
BTW, I will accept this as the right answer. – grokus Aug 9 '10 at 17:51
@grokus: * means to search forward for whatever word is under the cursor. – Daenyth Aug 9 '10 at 18:05
@Daenyth, thanks. I always thought that I wasn't too bad at Vim. (I could get things done) Today I'm reconsidering my position. – grokus Aug 9 '10 at 18:36
and to follow up @Daenyth, you can search backward for whatever word is under the cursor using #. These will match only on the full word. To search for the word under the cursor, including inside other words, use g* – Nathan Fellman Aug 9 '10 at 19:06

It sounds stupid but did you checked Caps-Lock?

share|improve this answer
yes I did. It was on "off" position. I have seen this behavior so many times so I was finally fed up and decided to get to the bottom of this. – grokus Aug 9 '10 at 16:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .