I'm reading through Steve Losh's Learn Vimscript the Hard Way and have added to my .vimrc
" make status line red while in insert mode
augroup hi_statusline
autocmd!
autocmd InsertEnter * hi StatusLine ctermbg=15 ctermfg=9
autocmd InsertLeave * hi StatusLine ctermbg=238 ctermfg=253
augroup END
I've noticed an odd behaviour, however. Sometimes I hit C-c to get out of insert mode, which works fine and is documented. When I do this, the InsertLeave event doesn't fire. When I use ESC it works fine. Is this a known oddity of vim? Is there perhaps a workaround, by hooking into another event that suggests InsertMode is no longer active?
EDIT | Meh, adding a inoremap <C-c> <ESC>
resolves it and as far as I can tell has absolutely no side-effects, since C-c already does what ESC does (goes back to normal mode). Correct me if I'm wrong.
:ino <C-C> <Esc>
^C is conventionally the get-me-out-of-here-now-please key, if you've got an autocmd you need to not run C-C becomes your friend.
This is documented under :help i_CTRL-C
:
CTRL-C Quit insert mode, go back to Normal mode. Do not check for
abbreviations. Does not trigger the |InsertLeave| autocommand
event.
As usual, Bram lives up to the design goals.
:help design-documented
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With