I've defined the following autocmds, which active/deactivate relative line numbers, depending on whether I'm in Insert mode or not:

" Relative line numbers, except Insert mode
augroup toggle_relative_number
autocmd InsertEnter * :setlocal norelativenumber
autocmd InsertLeave * :setlocal relativenumber

The problem I'm facing is that autocmd InsertLeave * :setlocal relativenumber only gets executed, when I leave Insert mode using Escape - not using Ctrl+C.

How can I also execute the autocmd, when I leave Insert mode using Ctrl+C.?

1 Answer 1


From :h i_CTRL-C (emphasis mine):

Quit insert mode, go back to Normal mode. Do not check for abbreviations. Does not trigger the InsertLeave autocommand event.

However, you could remap <C-c> as follows:

inoremap <C-c> <C-c>:doautocmd InsertLeave<CR>

if you really want to use Ctrl+c.


:h i_CTRL-C
:h :doautocmd
:h InsertLeave
  • 1
    Iow, don’t use C-c :) it breaks a lot things
    – D. Ben Knoble
    Sep 8, 2020 at 22:32
  • @D.BenKnoble I'm not sure what you mean. Sep 9, 2020 at 3:01
  • 1
    do never map <c-c>, you loose the ability to break existing running scripts. Sep 9, 2020 at 7:10
  • @ChristianBrabandt Would it be OK to map <C-c> as in the second example? It still sends <C-c> at the end, with additional steps. Sep 9, 2020 at 16:19
  • 1
    @JakeGrossman I am not sure. I thought as soon as you map <c-c> to something, you loose the ability to interrupt anything. even when it contains another <c-c>. But from my limited testing it seems to work. But I wouldn't bet on it. Sep 10, 2020 at 7:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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