Text search direction in Vim

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.


It sounds stupid but did you checked Caps-Lock?


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.

Tags:

Vim