Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Sometimes, after I select a suggestion (from the completion pop-up that appears when pressing Ctrl-N) using the Enter key, Vim will insert a newline and the cursor will be moved to the following line. This doesn't always happen - it seems that Vim tries to be smart about it and will only move me to the next line if it thinks this is what I would like.

However, I want to disable this behavior (because it is not always smart) so that I will always have to move to the next line by myself by manually pressing the Enter key. Is this possible?

share|improve this question
up vote 10 down vote accepted

What Vim does in response to your typing the <Enter> key while using insert completion depends on the state of the completion menu. The behavior of the menu is described here:

:help ins-completion-menu

and the behavior of various keys when using insert completion is described in the next section,

:help popupmenu-keys

where it explains that the behavior of the <Enter> key depends on the menu state. As I understand it, typing <Enter> inserts a newline except in the case where you have selected a match from the menu using cursor keys.

The best way to avoid inserting a newline when you don't want one is to terminate or make a selection using some other key such as Ctrl-Y or Ctrl-E.

See also

:help complete_CTRL-Y

and for the entire description if insert-mode completion,

:help ins-completion
share|improve this answer

I added this to .vimrc and now it behaves as I want:

noremap pumvisible() ? "\" : " "

share|improve this answer

You can add this mapping to your .vimrc file:

inoremap <expr> <CR> pumvisible() ? "\<C-Y>" : "\<CR>"

It will map the return key in insert mode to input CTRL-Y when the popup menu is visible. CTRL-Y selects the currently selected item in the menu without entering a new line. Otherwise it will make the return key act like normal.

share|improve this answer
Can you explain what this code does and how it addresses the problem given by the OP? Unexplained code can appear untrusted and dangerous to users. – bwDraco Jul 16 '15 at 1:56

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.