Why use Esc in vim?

11,386

Solution 1

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.

Solution 2

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.

Solution 3

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.

Solution 4

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 :/

Solution 5

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.

Share:
11,386
user537488
Author by

user537488

Updated on June 07, 2022

Comments

  • user537488
    user537488 almost 2 years

    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 ?

  • gimpf
    gimpf over 13 years
    This is similar to the equivalent Emacs interface: Use caps-lock for ctrl. Anything else and you get crazy.
  • Pascal Cuoq
    Pascal Cuoq over 13 years
    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.
  • mike3996
    mike3996 over 13 years
    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.
  • user537488
    user537488 over 13 years
    So don't caps lock blink everytime to distract you ?
  • Swiss
    Swiss over 13 years
    @Pascal It's actually mapped in vim, so it works in gVim also. See :help ^[
  • Jeffrey Jose
    Jeffrey Jose over 13 years
    @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
  • cdated
    cdated over 13 years
    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.
  • mike3996
    mike3996 almost 13 years
    @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.
  • sjas
    sjas almost 12 years
    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.
  • mike3996
    mike3996 almost 12 years
    @sjas, OTOH fewer programs support C-[ as Esc. (Of course talking about the X apps.) Sure, it is probably better to go that way.
  • sjas
    sjas almost 12 years
    It was asked specifically for vim, and not other programs. :)
  • mike3996
    mike3996 almost 12 years
    @sjas, hey---you brought up the "other programs" ;)
  • sjas
    sjas almost 12 years
    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
  • akdom
    akdom over 10 years
    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.