I like using the
<CR> key to confirm my selection in the popup menu. However I don't like the
<CR> key doing absolutely nothing when no item was selected in the menu -- in this case, it usually means I don't want to confirm a completion, I just want to insert a newline.
My current remap
inoremap <expr> <CR> pumvisible() ? "\<C-y>" : "\<CR>"
will "confirm the selection" and close the popup menu even if no item is selected -- i.e. the cursor stays in the same place. Is there another function I can use in the above ternary operation, or some other approach, that will give me the desired behavior?