I have these insert mode mappings in my .vimrc file:
imap <C-e> <C-o>A
imap <C-a> <C-o>I
They make Ctrl–A and Ctrl–E move the cursor to the start and end of the line without leaving insert mode, a la emacs keybindings.
However, I just realized that the Ctrl–E mapping introduces a conflict with the autocompletion submode. The documentation in :help complete_CTRL-E states:
When completion is active, you can use CTRL-E to stop it and go back to the originally typed text.
Thus, my Ctrl–E mapping interferes with this. Is there a way that I can make Ctrl–E jump to the end of the line only if auto-completion is not active?
There is no proper way to test whether the
Ctrl+X-completion mode is active or not.
However, the following two workarounds are possible.
1. If one uses the popup menu to choose from the list of available
completions (especially in the case of
menuoneset in thecompleteoptoption), an acceptable solution might be the mapping
2. A general solution can be based on a side effect: In the
completion submode, it is disallowed to enter Insert mode recursively
(see
:helpgrep Note: While completion), so if an attempt to do sofails, we can suppose that we are in the midst of a completion: