Because the keys d
and x
are used in normal mode to delete letters, I map <ctrl-d>
and <ctrl-x>
in insert mode to delete
and backspace
.
However, when I started to use completion plugin (I use supertab now, though it doesn't update recently, it still works good), if I press <ctrl-x>
in insert mode, vim jump into CTRL-X mode.
After searching, I found that key <ctrl-x>
actually predefined in ins-completion feature. Because using supertab I can use <tab>
to search completion, I still want to use <ctrl-x>
as backspace
in insert mode. Is there a way to do that?
1 Answer
It sounds as though the supertab plugin has either overwritten or removed your insert mode mapping. You can check if this is the case with the command:
:verbose imap <C-X>
You can reinstate your mapping simply by re-running your map command again:
:inoremap <C-X> <BS>
The best way to do this automatically in your vim configuration is probably to use the after
directory as suggested by @filbranden in the comments:
Create a .vim
file with any name in the location:
~/.vim/after/plugin/
with the contents:
inoremap <C-X> <BS>
This will be run after supertab (and all other plugins) and so can override its settings. See :help after-directory
for more details.
-
I execute
:verbose imap <C-X>
, it saysLast set from .......supertab\plugin\supertab.vim
Sep 2, 2019 at 13:34 -
I guess I can add autocmd to remap
<ctrl-x>
when I enter insert mode Sep 2, 2019 at 13:36 -
I add command
autocmd InsertEnter * inoremap <C-x> <BS>
in my .vimrc, and works, thank you Sep 2, 2019 at 13:47 -
The best way to override settings from plug-ins is in files under
~/.vim/after
, which are run after plug-ins load. In this case, puttinginoremap <C-x> <bs>
in~/.vim/after/plugin/ctrl-x.vim
(or any other file*.vim
in that directory) would solve that.– filbranden ♦Sep 2, 2019 at 17:55 -
1@filbranden Huh. For some reason I had it in my head when I wrote this answer that some plugin managers actually load plugins with
:runtime
rather than just manipulating the'rtp'
, in which case it would be arguably simpler just to move the setting further down in yourvimrc
. I can't find any evidence that this is true now, though. I'll update my answer to include your suggestion.– RichSep 3, 2019 at 9:44