I want to map , in normal mode to function as autocompleting a word <c-n> in insert mode. Also, I want to keep pressing , in normal mode to cycle through the list and then finally when I finish after choosing a word to still stay in normal mode.

Is this possible? The only way I can think of is to first map to i to enter insert mode. But then I don't want i mapped again in future iterations of ,.

1 Answer 1


The basic strategy is to use an expression mapping and check whether the popup menu is visible to issue the correct keys.

nnoremap <silent> , :call search('\w\>','cW')<cr>a<c-n>
inoremap <silent> <expr> , pumvisible() ? "\<c-n>" : ","

The normal mapping goes to the end of the word before trying to complete.

  • WOW! What if I also wanted to remain in normal mode after choosing?
    – domoremath
    Sep 5, 2017 at 15:53
  • 2
    What key press do you use to "choose" an entry? Obviously pressing escape works already. Two ideas would be to map <c-y> and <c-e> which are the "accept" and "cancel" commands, or add a CompleteDone autocommand which drops back to normal mode. Both of these have side-effects though, and are more complicated to implement. What about inoremap <silent><expr> <cr> pumvisible() ? "\<c-y>\<esc>" : "<cr>"
    – Mass
    Sep 5, 2017 at 16:13

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.