0

Foreword

Open a new file with vim -Nu NONE and insert the following text (| is to indicate the position of the cursor, in insert mode)

longline
lo|
longerline

Now hit Ctrl-XCtrl-N and the autocompletion list will pop up, and the first entry, longerline will be highlighted.

If you now hit Ctrl-Y, the autocompletion list will disappear and the line will be reverted to what it was, like in the snipped above. What's happened is described at complete_CTRL-Y.

If you hit Ctrl-Y again an n will be inserted, and if you keep hitting it, more an more letters will appear until the second line looks like the first one. What's happening is described at i_CTRL-Y.

The point is that two different functions correspond to Ctrl-Y depending on whether we are in insert mode with a completion list showing up or in insert mode without a completion list showing up.

The question

However, if now I enter :inoremap <C-Y> <C-O><C-Y> (which I requested here), then Ctrl-Y will have this mapped effect not only when I'm in insert mode without the pum showing up, but also with the pum showing up.

Is this a bug?

1
  • You ar mapping <C-y> while talking about <C-e>.
    – romainl
    Jan 10 at 6:53

1 Answer 1

1

Is this a bug?

This is not a Vim bug, if that is what you are asking, more like an oversight on your part and the part of the person who made the original suggestion.

This observation of yours is correct:

The point is that two different functions correspond to Ctrl-E depending on whether we are in insert mode with a completion list showing up or in insert mode without a completion list showing up.

The problem is just that you didn't proceed to the logical conclusion, which that you need to take the presence of the popup menu in account if you want your mapping to override the native functionality in one case while preserving it in the other.

This is typically done with an :help <expr> mapping:

inoremap <expr> <C-e> pumvisible() ? "\<C-e>" : "\<C-O>\<C-e>"

where you use a ternary expression to do a plain <C-e> if the popup menu is visible or a fancy <C-o><C-e> if it is not.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.