4

I use ctrl-p (and SuperTab with it), quite often to do autocompletion. But what happens quite often is that I press tab to autocomplete, I get the match I want, and then I have to go into normal mode. But when I press escape, it cancels out of the autocompletion. Is there anyway to select the autocompletion choice and then go into normal mode immediately without it canceling?

I know continuing to type will accept the autocompletion by default, but quite often I need to jump to a word, delete it, and type out another word, and then jump back to normal mode (I'd imagine I'm not alone in this). It would be useful to have tab autocompletion available in this scenario.

So is there anything I can press to accept the autocompletion and go into normal mode, without canceling it?

  • Selecting a suggestion always leaves you in insert mode. Insert mode completion would be useless if it left you in normal mode after completion. – romainl Jul 6 '15 at 6:56
  • In the title and first paragraph you say you want to go to normal mode, but at the end of the first paragraph and in the last paragraph you say you want to go to insert mode. Which is it? O.o – muru Jul 6 '15 at 7:53
  • I'm sorry I mistyped. I just want a way to autocomplete my word and then go into normal mode immediately after. – OceansOnPluto Jul 6 '15 at 11:05
3

You can use ctrl-e to cancel a selection, and ctrl-y to accept it (followed by ESC to go to normal mode). People usually use ESC to cancel a selection (escape from whatever happens), and also map Enter to complete a selection, if one is active:

inoremap <expr> <silent> <cr> pumvisible() ? "<c-y>" : "<cr>"

If you still want to "complete and go to normal mode" on hitting ESC, you can use something like this instead:

inoremap <expr> <silent> <esc> pumvisible() ? "<c-y><esc>" : "<esc>"

You'll probably have to rely on ctrl-e more now, to cancel a selection (or delete characters with BACKSPACE) ...

BTW, check your ESC mapping - I can very well complete with ctrl-n and use ESC with no problems afterwards.

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.