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.

share|improve this question
1  
+1 for "Learn Vimscript the Hard Way) reference, seems very useful! – mMontu May 25 '12 at 15:58
    
<C-c> really means: abort all running operations. This includes scripts, and autocommands are scripts. Simple as that. – sehe May 25 '12 at 21:17
up vote 10 down vote accepted
: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.

share|improve this answer
    
Thanks, also figured this out just before you posted too ;) Will accept your answer once the 5 minute timeout passes and SO lets me do it ;) I had C-c mapped to ESC in my vimrc previously, but had removed it since it I realised it already supported the behaviour... obviously with this subtlety though. – d11wtq May 25 '12 at 15:27
1  
np, accept+upvote actually feels like overkill for this. Glad it's workin for ya :-) – jthill May 25 '12 at 15:33

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
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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