Text search direction in Vim

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.


Solution 1:

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.

Solution 2:

It sounds stupid but did you checked Caps-Lock?

Solution 3:

Nathan has already answered why this happens, but if you use both directions regularly and want n to always look ahead and N to always look back, no matter which way you searched, you can put this in your .vimrc:

nmap n /<CR>
nmap N ?<CR>

/ and ? without parameters perform the last search, in their respective (absolute) directions.