15

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

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

  • 1
    Eyup, that's the Vim way. Another common way promoted by Learn Vim the Hard Way (book) is inoremap jk <Esc> – grochmal Dec 24 '16 at 16:37
  • This is a nice solution, but what is the problem to use only Ctrl+Enter+j? – Sandra Ross Dec 24 '16 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. – Konrad Rudolph Dec 24 '16 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. – Sandra Ross Dec 24 '16 at 16:48
  • @SandraRoss For that, inoremap <C-j> <Esc> should work. :-) – Konrad Rudolph Dec 24 '16 at 16:52
27

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

  • 3
    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 Mar 6 '18 at 7:53
9

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.

  • I know exactly what you mean. I've seen that earlier this week – Sandra Ross Dec 24 '16 at 3:05
  • I would do that, but I use CapsLock as my Compose key (: – DopeGhoti Jul 27 '18 at 20:11
6

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.

  • CTRL-C is ASCII 0x03, sends SIGINT to the shell -- isn't the same as ESC. – cat Dec 24 '16 at 0:59
  • @cat It works basically the same in vim though. I am always using Ctrl-C instead of Esc – Erik W Dec 24 '16 at 2:54
  • 1
    @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. – Lightness Races in Orbit Dec 24 '16 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! – Lightness Races in Orbit Dec 24 '16 at 16:54
  • 1
    @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 Dec 24 '16 at 17:06
-3

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.

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

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.