53

I'm having a problem with the Esc key when I want to return to the interactive mode from the insert mode. Is there exist another key used to release the insert mode.

5
  • 25
    Press control [ Commented Dec 23, 2016 at 20:51
  • 3
    Quite a few suggestions over on vi.stackexchange.com/q/300/9708 too.
    – Guy
    Commented Dec 23, 2016 at 23:20
  • 4
    new Macbook Pro? <grin> Commented Dec 24, 2016 at 10:05
  • 3
    no, thinkpad x1 carbon Commented Dec 24, 2016 at 12:17
  • 1
    @RuiFRibeiro. If you happen to be on a MacBook, press control+c to exit insert mode. And the esc-not-working problem on macOS is probably caused by a frozen Siri, if not caused by hardware issue. Just go to Activity Monitor to force quit Siri, then you might solve the esc problem completely. ^_^
    – Scott Yang
    Commented Mar 2, 2023 at 16:48

7 Answers 7

75

Ctrl-[ sends the same character to the terminal as the physical Esc key. The latter is simply a shortcut for the former, generally.

1
  • 6
    I once had a real vt220 terminal, and its keyboard does not have a Escape key. Pressing Ctrl+[ was the only way to generate Escape.
    – Kusalananda
    Commented Mar 6, 2018 at 7:53
32

You could try Ctrl-C, that works for me and is in my opinion easier than ESC. However I am not sure if it is enabled by default.

12
  • CTRL-C is ASCII 0x03, sends SIGINT to the shell -- isn't the same as ESC.
    – cat
    Commented Dec 24, 2016 at 0:59
  • @cat It works basically the same in vim though. I am always using Ctrl-C instead of Esc
    – Erik W
    Commented Dec 24, 2016 at 2:54
  • 2
    @cat: You do get it for free, because vim has that handler in place. You don't have to do anything yourself. This answer works out of the box; I just tried it. Does it work in general for any application? No, but that's not what was asked for. Commented Dec 24, 2016 at 16:44
  • 2
    @cat: Really? The title is "How to send the ESC signal to vim when my esc key doesn't work?", the only tag is vim, and the problem described in the question is about escaping Vim's insertion mode. Here is the summarising part of the question: "Is there exist another key used to release the insert mode." If that's not specific to Vim and its insert mode, then I don't know what is! Commented Dec 24, 2016 at 16:54
  • 2
    @LightnessRacesinOrbit Well, when I saw the title initially, it was "Another key used for Esc" and the question didn't look specific to vim at at all. sorry! ¯_(ツ)_/¯
    – cat
    Commented Dec 24, 2016 at 17:06
14

If you want to be able to use a single key, as a pure *nix solution (without Vim mappings) you could define another key as Esc. Just like Emacs users remap CapsLock to Ctrl some Vim users (me included) remap CapsLock to Esc. This works for any *nix using X11.

Use xev -event keyboard (and then press CapsLock) to get the keycode for the CapsLock key (for me it is keycode 66). Then you can use xmodmap to remap the key:

xmodmap -e 'remove Lock = Caps_Lock' -e 'keycode 66 = Escape'

To get this at login you can add the xmodmap expressions to ~/.Xmodmap as follows:

remove Lock = Caps_Lock
keycode 66 = Escape

Although for the second part YMMV, since not all display managers run ~/.Xmodmap. You may need to add xmodmap .Xmodmap to .xinitrc on some of them.

2
  • I know exactly what you mean. I've seen that earlier this week Commented Dec 24, 2016 at 3:05
  • I would do that, but I use CapsLock as my Compose key (:
    – DopeGhoti
    Commented Jul 27, 2018 at 20:11
8

Existing solutions notwithstanding, the conventional solution in Vim is to remap keys in your .vimrc configuration. In fact, many Vim users have an easier reachable key remapped to Esc. Popular choices are Ctrl+Enter, or jj, etc.

To enable this, just put something like the following into your .vimrc and reload it/restart Vim:

" Shift-Enter
inoremap <S-CR> <Esc>
" Double-j
inoremap jj <Esc>

More information and alternatives

6
  • 1
    Eyup, that's the Vim way. Another common way promoted by Learn Vim the Hard Way (book) is inoremap jk <Esc>
    – grochmal
    Commented Dec 24, 2016 at 16:37
  • This is a nice solution, but what is the problem to use only Ctrl+Enter+j? Commented Dec 24, 2016 at 16:38
  • @SandraRoss You can really use any key combination you fancy (though beware that some, e.g. Ctrl-Enter, don’t work on macOS). That said, Ctrl+Enter+j strikes me as more difficult to type, and I honestly don’t know whether you can even configure three-key combinations with two non-modifier keys (Enter, j) in Vim. Commented Dec 24, 2016 at 16:38
  • Ok, I undertand. In fact, Ctrl+Enter+jj doesn't work for me, because, indeed, I use macos X. At least, could you tell me what I have to enter for just Ctrl+j. Commented Dec 24, 2016 at 16:48
  • @SandraRoss For that, inoremap <C-j> <Esc> should work. :-) Commented Dec 24, 2016 at 16:52
2

Terminal emulators send an ESC code also when you press:

  • Ctrl+[
  • Ctrl+3 I like this one as you can use one hand only to press it.
  • Alt followed by any other key. For example Alt+h,j,k,l will exit insert mode and move the cursor at the same time.
0
0

There's an issue in Siri that prevents some systems from reading ESC.

If that's the case, the following command should fix it:

killall Siri 
-2

Ctrl + F2

Is enabled by default. No need to configure any settings.

You will move to normal mode, where you can do :q! or :wq.

1
  • 3
    Ctrl+F2 may send an escape, but it will also send other things.
    – Kusalananda
    Commented Mar 6, 2018 at 7:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .