Having decided to use the arrow keys to navigate instead of hjkl, and having decided that I want to move to the previous screen line, not actual text line, I have put this on vimrc

nnoremap <Up>   gk
nnoremap <Down> gj
xnoremap <Up>   gk
xnoremap <Down> gj
inoremap <Up>   <C-o>gk
inoremap <Down> <C-o>gj

This conflicts with omnicomplete, because it wants to use the arrows to navigate the completions offered. I can still navigate with CTRL-N and CTRL-P, but I much would prefer to use the arrows to choose my autocompletion. Is there any way to configure omnicomplete to use my gj gk

1 Answer 1


You can solve this by using an expression mapping to send CTRL-N/CTRL-P during completion. e.g.

:inoremap <expr> <Up> pumvisible() ? '<C-P>' : '<C-O>gk'
:inoremap <expr> <Down> pumvisible() ? '<C-N>' : '<C-O>gj'
  • Sorry, the OP wanted to type gj to move down in the popup; yet, you might want to type an actual g. This would be annoying (to me at least) so mapping other keys is a better idea.
    – D. Ben Knoble
    Aug 12, 2023 at 11:59
  • 1
    @D.BenKnoble I think the OP actually wants to use up and down in the popup, and they asked how to configure the popup to accept the mapping’s rhs gj in order to achieve this. I’ve tackled it a different way (because their suggestion isn’t possible).
    – Rich
    Aug 12, 2023 at 16:24
  • 1
    Oooohhh. My bad. Really misread that.
    – D. Ben Knoble
    Aug 12, 2023 at 23:26
  • Yes, I do not want to use g or gj ever in my life. Sorry bad habits, but hard to remove. I wish I can do everything with arrow keys.
    – Rho Phi
    Aug 24, 2023 at 15:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.