I have a strange problem with completion and my cursor movement redefinitions and the excellent jedi-vim plugin with supertab. I have in my .vimrc these maps for vertical movement in visual lines:

" Visual movement with the arrows and End-Home 
nnoremap <Down> gj
nnoremap <Up> gk
vnoremap <Down> gj
vnoremap <Up> gk
" these create problems with completions...
inoremap <Down> <C-o>gj
inoremap <Up> <C-o>gk
inoremap <Home> <C-o>g<Home>
inoremap <End>  <C-o>g<End>

...and the second group is almost always ok, but it creates problems with completions only in python files, using jed-vim. The effect is that if I have the expansion suggestions on:

enter image description here

and press one of the up/down arrow keys I have the literal "gj" added:

enter image description here

...but this thing does not happen for example with latex completions:

enter image description here

which is ok after a <Up> selection (although with a "bip" which is suspicious...).

So my question is: it is possible to have the aforementioned inoremap definition in normal insert mode, but automatically removed/ignored when in supertab completion mode?

  • I don't know if it will fix your issue, but maybe you could slightly modify your mappings so that they test if the popup menu is visible or not: inoremap <expr> <Down> pumvisible() ? '<C-N>' : '<C-O>gj' and inoremap <expr> <Up> pumvisible() ? '<C-P>' : '<C-O>gk' Commented May 14, 2016 at 10:36
  • @user9433424 --- it works! Can you post this as an answer? Thanks!
    – Rmano
    Commented May 14, 2016 at 10:40

1 Answer 1


I don't use your plugins so I can't be entirely sure it will fix your issue, but it seems you want mappings in insert mode which behave differently depending on whether the popup menu is visible or not.

You can use the pumvisible() function to test if the popup menu is visible, it returns 0 when it's not, 1 otherwise.

Then you can build an expression with the ternary operator ?: (see :h expr1 for more info) to return a different string depending on the state of the popup menu. For example:

pumvisible() ? '<C-N>' : '<C-O>gj'

This expression returns the string '<C-N>' when the popup menu is visible (which contains a key you can hit to select the next item in the menu), or '<C-O>gj' (which contains a key you can hit to go down one line).

Finally, you need to tell your mapping that it must not type the {rhs} directly but first evaluate it as an expression. To do so, you can pass to :inoremap the argument <expr>.

It could give something like:

inoremap <expr> <Down> pumvisible() ? '<C-N>' : '<C-O>gj'

And something similar for <Up>:

inoremap <expr> <Up> pumvisible() ? '<C-P>' : '<C-O>gk'

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.