20

The Vi editor was originally written on an ADM-3A terminal, which had the Escape key in place of the Tab key (compared to most modern keyboards). Many touch typists appreciate the fact that they can leave their hands on the keyboard home row while using Vim but the use of Esc makes it compulsory to leave the hands to press Esc. I am currently learning vim. Should remap Esc to somewhere else ? What is the most common remap for this case ? or should I leave the idea of remapping Esc and continue using it ? What do pro users of vim do ?

2
  • khachik: but ergonomics can be objective. Leaving the home row for some very common operation means bad ergonomics.
    – mike3996
    Dec 11, 2010 at 11:40
  • 23
    why do you copy part of a text (vim.wikia.com/wiki/Avoid_the_escape_key) in which the answer is already given?
    – DaVinci
    Dec 11, 2010 at 11:41

11 Answers 11

23

An alternative for the esc key is CTRL+[ combination.
(This is a standard in VIM, no need to remap anything).

I use this shortcut all the time instead of Esc.

Also I remapped my caps lock key to Ctrl, that way it is even easier to type.

5
  • 15
    It's more "standard in terminals everywhere" than "standard in VIM". Traditionally, Ctrl-A produce ASCII code 1, Ctrl-B code 2, ... Ctrl-Z code 26, and by continuity, Ctrl-[ is mapped to ASCII code 27, ESC. Dec 11, 2010 at 11:59
  • 1
    So don't caps lock blink everytime to distract you ?
    – user537488
    Dec 11, 2010 at 16:36
  • @Pascal It's actually mapped in vim, so it works in gVim also. See :help ^[
    – Swiss
    Dec 11, 2010 at 19:34
  • 2
    Why didn't anyone tell me Ctrl-[ is the same as escape, I feel like my finger has been making those long journeys to the escape key for nothing. I'm with you on the cap-lock, incidentally I picked up that habit from emacs, but considering how often I press Ctrl-c.
    – cdated
    Dec 14, 2010 at 5:25
  • @user537488: no it doesn't usually blink -- depends on how you mapped it. My gentoo linux doesn't recognize the caps lock (so it doesn't blink at all) nor does windows xp. Debian, on the other hand oddly blinks. The LED is controlled by the OS so if it sees a Ctrl or Esc instead of Caps lock, then it doesn't have to know anything else.
    – mike3996
    May 6, 2011 at 11:42
21

I have mapped Escape to otherwise unused Caps Lock. This is a common method to streamline vim's usage. This article has some alternative solutions, too. The same article links to tweaks to make the Escape-Capslock switch system-wide if you prefer.

6
  • 4
    This is similar to the equivalent Emacs interface: Use caps-lock for ctrl. Anything else and you get crazy.
    – gimpf
    Dec 11, 2010 at 11:42
  • 2
    Remapping capslock to CTRL and using CTRL+[ instead of escape is the better way to go IMHO. It's almost as fine in VIM and even better for other programs.
    – sjas
    Jul 10, 2012 at 10:48
  • @sjas, OTOH fewer programs support C-[ as Esc. (Of course talking about the X apps.) Sure, it is probably better to go that way.
    – mike3996
    Jul 10, 2012 at 10:50
  • It was asked specifically for vim, and not other programs. :)
    – sjas
    Jul 10, 2012 at 10:51
  • 1
    Haha, true but unintentionally. I was thinking of having a better reachable CTRL key you can use in other applications, too. Because IMHO you need CTRL way more often than ESC. :D
    – sjas
    Jul 10, 2012 at 10:53
8

I have the key sequence jk mapped to Esc.

You might ask, so what happens when you come across a word with jk. No problem. Type j, wait for half a second and then type k. Yes, that's non-ideal but the advantages of not having to move your hands of home row is much more.

I highly recommend jk sequence as `Esc.

Other variations of the same idea are jj - which in my humble opinion wont work for me. I use j for moving down - as others.

2
  • 1
    But that jj could be mapped to insert mode only. Though, if one spends a lot time in visual or command line mode, then a mapping such as jk makes more sense! Hadn't thought of that.
    – mike3996
    Dec 11, 2010 at 13:54
  • 2
    @progo, You're right. jj imap'd will work just fine. But I'm still leaning towards jk and this time my argument ( :) ) is that jk anyway is a NOOP (move down-move up) .. just like Esc Dec 13, 2010 at 2:42
6

I remap Esc to Caps systemwide.

In Linux:

Create a file ".Xmodmap" in your home directory, with the following content:

clear Lock
keysym Escape = Caps_Lock
keysym Caps_Lock = Escape

In Mac:

Download a program called "KeyRemap4MacBook" and remap tab to Esc.

Using other people's computer becomes a pain in the ass though. I'm such an environment tweaker that I look like my grandma on a standard setup :/

3

CtrlC also works for escape out of the box. I've got my Capslock key mapped to Ctrl as that's more useful to me in a number of situations.

1
  • Ctrl-C should be used with care as most plugins don't respond well when it is sent... sometimes this will even result in plugin crashes and bizarre behavior that is difficult to reproduce.
    – akdom
    Jan 2, 2014 at 1:52
2

I have personally remapped <ESC> to ii.

ito go in and ii to go out of insert mode is easy to remember.

2

I mapped mine with ;; and my right pinky finger is now aching, this is after a month of coding. I think it's a good decision to go with jj or jk.

1

I use Menu key instead of escape.

Details are here: How to map Menu key ("Application key") to Escape key in vim?

0

I rebinded capslock to control and right control to escape key, so pressing escape is just fine now.

0
imap jj <ESC>

Others like to map 'jk', or 'leader-j'. I don't use hjkl nearly as much as I should.

0

I've remapped it to my right ⌘ (mac keyboard) because it works always no matter what mode you're in or application.

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