Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim InsertLeave event doesn't occur when using CTRL-C instead of ESC

Tags:

vim

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.

like image 476
d11wtq Avatar asked May 25 '12 15:05

d11wtq


2 Answers

: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.

like image 181
jthill Avatar answered Sep 21 '22 04:09

jthill


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
like image 45
benjifisher Avatar answered Sep 19 '22 04:09

benjifisher