When vim suggests completions, I can discard them without accepting with Ctrl+y

I would like to remap that shortcut to Escape while keeping the usual behavior of Escape (exit insert mode) when no suggestion box is visible.

The answer provided here https://stackoverflow.com/a/50033076/13801624 lead me to try inoremap <expr> <Esc> pumvisible() ? "<C-y>" : "<Esc>" however this just makes Escape do nothing when a suggestion box is visible.

  • I think you want to use C-E to end completion (see here: github.com/vim/vim/blob/master/runtime/doc/…) Sep 27, 2021 at 21:12
  • @ChristianBrabandt That is true once you have selected one of the suggestions, but even then, it reverts but doesn't close the suggestion box. In my case I use Tab to scroll through the suggestions, therefore C-y allows me to close that box and be able to use Tab to insert a tab. The interesting part is that C-y does what I want, but I am unable to remap Esc to replicate that sequence Sep 27, 2021 at 21:24
  • I don't see that. Please give complete reproduction steps Sep 28, 2021 at 6:23
  • Don’t map escape. It’s going to cause all kinds of trouble.
    – D. Ben Knoble
    Sep 28, 2021 at 11:07
  • Got it - I will find another way then. Oct 1, 2021 at 14:33


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.