First, let's deconstruct the mapping you got from that page:
inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
inoremap
makes it a non-recursive insert mode mapping. i
means "insert mode" and nore
means "non-recursive". I know the remap
at the end makes it tempting to call those things "remaps" or "remappings" but they are not. They are just "mappings".
<expr>
makes it an expression mapping. It means that the right-hand side is an expression that is going to be evaluated at runtime to produce the actual RHS.
pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
is what Vim calls a "trinary operator" (AKA ternary operator): :help trinary
. In plain english, it reads like this: "if the popup menu is visible, return <C-y>
, if not, return <C-g>u<CR>
".
:help complete_ctrl-y
accepts the current suggestion in the popup menu.
:help ctrl-g_u
prevents Vim from inserting an undo point before <CR>
. It is not strictly necessary but good practice.
You want to adjust the mapping's behaviour when you accept a suggestion so it is the "\<C-y>"
part that must be changed.
Now…
- you already know what key to press to leave insert mode,
- you can take a look at
:help key-notation
if you are unsure how to represent that key,
- you know what part of the mapping you need to change,
- you should get an idea of how to proceed just by looking at the two last parts of the "trinary" operator.