9

I have recently found out that Ctrl+C can be used instead of Esc in certain instances. Getting out of insert mode for instance. Other things can only exclusively exited using escape.
So my question is, is it possible to completely replace the escape key with Ctrl+C? So that it works exactly the same?

2 Answers 2

9

There are some (often subtle) differences between Esc and CTRL+C to leave Insert mode.

For instance, :help i_CTRL-C mentions some of them:

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

Another difference happens when you enter Insert mode with a count, in which case CTRL+C will cancel the repetition from the count. To illustrate, 3iabc<Esc> will insert abcabcabc, while 3iabc<C-c> will insert simply abc.

If you want to make CTRL+C exactly equivalent to Esc, you can use a mapping to do so:

imap <C-c> <Esc>

Another option (if you're looking for a replacement for the Esc key, either because your keyboard doesn't have one or because you find its location inconvenient) is to use CTRL+[, which is exactly equivalent to Esc, it produces the exact same keystroke so both key combinations are effectively indistinguishable to Vim.

7
  • Yeah problem is, my keyboard layout makes control-] unreachable. Is there really no way to just remap it to c-c Jun 6, 2020 at 18:19
  • 1
    @user2741831 Yes there is, see the answer, imap <C-c> <Esc> might be exactly what you want to make <C-c> behave exactly like <Esc>. You might want to also map that in other modes (Visual, Select, etc.) Perhaps in all modes: map <C-c> <Esc> and map! <C-c> <Esc> will do that.
    – filbranden
    Jun 6, 2020 at 18:21
  • 2
    Any reason not to noremap instead of map?
    – D. Ben Knoble
    Jun 7, 2020 at 12:34
  • @D.BenKnoble I thought this was one case where using a recursive map was appropriate, since it's likely you want to replace the key in all contexts and that potentially includes other mappings. Does that make sense?
    – filbranden
    Jun 7, 2020 at 13:35
  • 3
    @filbranden kind of? The mapping being recursive only means remapping escape also affects ctrl-c..
    – D. Ben Knoble
    Jun 7, 2020 at 13:53
3

I do not think it is good idea to use CTRL-C instead of ESC since it does not do some useful things like following (from :h i_CTRL-C) and can break some plugins.

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

But if really want it you can remap:

inoremap <ESC> <C-C>

Also you maybe want to know that <C-[> is equal to <ESC>. And if you worry about speed of typing think about this mapping:

inoremap jj <Esc>
1
  • Note that your first inoremap is backwards, you're mapping Esc to Ctrl-C and not Ctrl-C to Esc. With the second mapping, you might want to explain what that does and why you'd use that, it might not be obvious to a beginner...
    – filbranden
    Jun 7, 2020 at 13:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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