I want to select the 6th item (here readImage) in the auto-completion items.

enter image description here

The normal way i knew is pressing ctrln for 6 times until the matched word is selected and then press enter.

I tried different solutions:

  1. With the mouse:

    :set mouse=a 

    then moving my cursor on the 6th word,and clicking mouse,no effect.

  2. By entering a number:

    Pressing 6, no effect.

What is your smart way to select matched item in auto-completion?

My vim version on mouse is the following:

vim --version | tr -s  " " "\n" |grep mouse
  • 1
    Skimming ':h compl-generic' suggests this is a feature request.
    – Rob Mosher
    Jul 13, 2017 at 17:35
  • @RobMosher do you mean this question is a feature request or the ability to select items using a number has been requested already?
    – D. Ben Knoble
    Dec 23, 2018 at 4:28

2 Answers 2


You can select the currently highlighted :h ins-completion by pressing Ctrl-y and discard the completions and go back to original text by pressing Ctrl-E. For more information, see :h complete_CTRL-E and :h complete_CTRL-Y

  • Ctrl-E
    When completion is active you can use CTRL-E to stop it and go back to the originally typed text. The CTRL-E will not be inserted.

  • Ctrl-Y
    When the popup menu is displayed you can use CTRL-Y to stop completion and accept the currently selected entry. The CTRL-Y is not inserted. Typing a space, Enter, or some other unprintable character will leave completion mode and insert that typed character.

For some more completion-menu keys, you can read :h popupmenu-keys

  • Looks like OP wants to be able to select non-current item with a mouse or some shortcut avoiding C-n/C-p
    – Maxim Kim
    May 15, 2019 at 7:34

patch 8.1.1068 introduced a new function :h complete_info:

    patch 8.1.1068: cannot get all the information about current completion

    Problem:    Cannot get all the information about current completion.
    Solution:   Add complete_info(). (Shougo, Hirohito Higashi, closes #4106)

You can create map like this:

" map 1-9 to nth item
" map shift+{1-9} to last nth item
let s:shiftKeys = '!@#$%^&*('
for s:i in range(1, 9)
  exe printf('inoremap <expr> %d pumvisible() ? <sid>select_pum(%d - 1) : %d ', s:i, s:i, s:i)
  let skey = s:shiftKeys[s:i-1]
  exe printf('inoremap <expr> %s pumvisible() ? <sid>select_pum(-%d) : "%s" ', skey, s:i, skey)

" map 0 to original item
inoremap <expr> 0 pumvisible() ? '<c-e>' : 0

function! s:select_pum(index)
  let compInfo = complete_info()
  let idx = a:index >= 0 ? a:index : a:index + len(compInfo.items)
  let d = idx - compInfo.selected
  return repeat( d > 0 ? "\<c-n>" : "\<c-p>", abs(d))

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.