I can customize the n and N keys to always search backward and forward respectively irrespective of what the last search direction was with the following commands:

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

I want to achieve similar effects for the , and ; keys, i.e. I want , to always jump backward and ; to always jump forward. But I can't find any similar variable in :h eval.txt for this purpose. Maybe I'm missing some thing.

How do I make , and ; unaware of the direction of the latest f,F or t,T command?

nnoremap <expr> ; getcharsearch().forward ? ';':','
nnoremap <expr> , getcharsearch().forward ? ',':';'

check :h getcharsearch()

  • 1
    The whole thing was in fact in :h eval.txt. Don't know why I missed it.
    – klaus
    May 1 '19 at 5:42

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.