I have the following mapping:
inoremap <expr><CR> pumvisible() && complete_info().selected != -1? "\<C-y>" : "\<CR>"
inoremap <expr><Space> pumvisible() && complete_info().selected != -1? "\<C-y>" : "\<Space>"
The idea here is that if I have a completion menu open & and item selected, then pressing Enter
or Space
will select that item from the completion menu. Notice that <C-y>
is the built-in combination to confirm a selection. This works fine.
Now, I want to expand the functionality of this so that whenever I press Space
, it will select an item from the list and type a literal whitespace. I tried the following:
inoremap <expr><Space> pumvisible() && complete_info().selected != -1? "\<C-y>\<Space>" : "\<Space>"
This does not work (it behaves as if only space was pressed), & I suspect it's because the keys are sent simultaneously. I tried using a regular space character instead of the symbol and it behaved the same way. What can I do?
EDIT: Just to make my question clearer, here is what happens when I select an autocompletion option using the Enter
key:
No problems here, all works as intended. What I want to do now is that if I had pressed Space
instead of Enter
, then it would do the exact same thing as it did before, but also add a whitespace at the end. With the current settings I am using, this is what happens instead: