2

Sometimes n (next instance of a search) starts moving me up in the file instead of down. Could this be caused by a bug in a plugin?

  • What does verbose map n report? – muru Feb 8 '17 at 3:24
  • 1
    verbose map n said no mapping found. – SU3 Feb 8 '17 at 6:35
6

'n' by default moves in the same direction as the last normal mode search command. So if you used ? to search backwards, n will also search backwards. Until you use / again to search forward, in which case n will then again also move forward again. The same is true for N.

Here is a mapping that I use to have n always search forwards and N always continue searching backwards:

nnoremap <expr> n (v:searchforward ? 'n' : 'N')
nnoremap <expr> N (v:searchforward ? 'N' : 'n')

See also this answer where I explain that in more detail and also how those maps work.

| improve this answer | |

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.