Vim logo vim online Vim Book Ad

basic Tip #285: Don't use the escape key!

 tip karma   Rating 150/67, Viewed by 4379 

created:   July 22, 2002 10:26      complexity:   basic
author:   David A. Rogers      as of Vim:   5.7

Vim (any vi really) is a dream for touch typists... Until you want to switch from insert mode to normal mode.  Then you've got to reach way up to whack the escape key.

Or at least that's what I was doing until I realized that (drum roll please)

                    Esc is exactly equivalent to control-[  (that's the control key plus the left square bracket key)


That little bit of knowledge, plus mapping my caps lock to another control key, was what turned my fascination with Vim into true love.  You never have to lose track of the home row again!

For Xfree86 users - you can make the capslock key another control key by adding

Option "XkbOptions" "ctrl:nocaps"

to the InputDevice section of your XF86Config file.

For Windows NT/2000 users  - use the following .reg file to do the same thing:

REGEDIT4

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,02,00,00,00,1d,00,3a,00,00,00,00,00

 rate this tip  Life Changing Helpful Unfulfilling 

<<Mapping to print syntax highlighted buffer in B&W; | Recover after doing something... ugly. >>

Additional Notes

[email protected], July 24, 2002 12:25

I was also frustrated by location of ESC and CONTROL when using vim. My solution was to buy two Happy Hacking keyboards:

http://www.pfuca.com/products/hhkb/hhkblite2.html

Not only does it have ESC and CONTROL where I want them, but it makes it easier to switch between my Mac computer
at work and my FreeBSD box at home.
[email protected], July 25, 2002 12:01
I've used Ctrl-[ for a long time-- I guess at some point over the years it ceased being obvious.
As for the ctrl/caps lock under NT, I use:
00 00 00 00 00 00 00 00 03 00 00 00 1d 00 3a 00 3a 00 1d 00 00 00 00 00

which swaps the caps lock and ctrl keys.  Format is 2 dwords of 0, 1 dword length (#mappings + 1), dword mappings (input scan code 16-bit, output scan code 16-bit), final dword of 0.  Can remap any keys this way, even the Esc and ~ key to make your keyboard work like a happy hacking one.

Sanjay
Anonymous, July 25, 2002 14:01

What could I put in my XFree86 config file to turn Caps Lock into Ctrl-[ instead of just making it a control modifier key?

In other words, I want CapsLock keystroke to generate "Ctrl-[" key symbol.

Thanks.
jf_____ /at/ fastmail (.) fm, July 26, 2002 1:17
hey neat! I must say that I hadnt realized that about Ctrl-]. Nice to see that somebody was thinking along (well, sorta) the same lines as me. I was in fact just a few minutes ago working for an alternative solution to the problematic "<esc>" key, when something struck me.

I've always had situations where I had to "make a quick insert" - go into insert mode, insert a quick word, then come out into normal mode, and navigate elsewhere. To make a long story short, this is the solution that I came up with -

:map! <S-space> <esc>

or even
:map! <S-space><S-space> <esc>
if you find the first mapping getting in the may of your typing

With this quick combo ("Shift", + <space>), one can easily (and might I add, intuitively) go into and come out of insert mode. I guess I always thought the <space> would be a good way to do this sort of thing, since it is after all, so intuitive in the typing process. So why not make it such that it can "escape" you out into normal mode as well? Just type 'i', to go into insert mode, type in your stuff, and once you're done, hit Shift-space!

(note: I havent automated 'i' into the whole process yet, but does anybody think that it would be possible? I would certainly like to hear about it if you do work out something)
dubu AT gmx.net, July 26, 2002 17:35
I changed my CapsLock key to Escape under XFree86 with the following lines in my ~/.Xmodmap:

  ! Esc on caps lock :-))
  remove Lock = Caps_Lock
  keysym Caps_Lock = Escape

In my ~/.xinitrc, xmodmap is called to set the mapping:

  if [ -f ~/.Xmodmap ]; then
      xmodmap ~/.Xmodmap
  fi

Finally, my typing speed in vim is the same as with the original HP 9000 ITF HIL keyboards, which MUST have been designed by vi hackers  (Esc key on the outer left, next to the shift key). :-)
Anonymous, August 11, 2002 6:29
This is not a good tip if you have e.g. norwegian keyboard layout.
ctrl [ for me is pressing CTRL+Alt Gr + 9
grinderf at adelphia.net, August 20, 2002 20:35
i don't know if it's the "proper" way to do it, but i've always used ctrl+c myself
[email protected], October 8, 2002 23:35
I have a better tip.

You can use some useful 'imap' keymaps for inserting mode...

for example :
<C-j> <ESC>lji
<C-k> <ESC>lki
<C-u> <ESC>i
<C-l> <ESC> l

<C-h> is crash with scancode of Insert key... so I use <C-u> keymap

Frankly speaking, I bring this ideas from emacs keymaps.

Anyway, if you do so you can move your cursors freely everytimes. :)
Anonymous, October 13, 2002 21:57
Lots of great adivse here!
I love using shift-spacebar for esc
Thanks
Mark, November 11, 2002 15:50
Thanks for the tip on Shift-Spacebar for ESC
[email protected], November 21, 2002 1:03
The shift-space mapping is good thinking indeed.
Esc is way too cumbersome
Anonymous, December 26, 2002 1:46
Since on the french canadian keyboard the key combination CRTR-[ is perform with CTRL+AltCar+"the cedilla key" it's not very convinient.

But the TIP of using CTRL-C key combination work well on any keyboard mapping. It doesn't required you to modify any keymap, so it will work on any vanilla installation. From my point of view (switching from PC with English_US and Frech_CA keyboard layout) using CTRL-C instead of the hard to reach ESC key is the real TIP here.
Anonymous, January 14, 2003 22:22
I cannot get 'map! <S-space> <esc>' to work for me. I am running Vim throught a terminal client(putty), would this effect this mapping to not work.   I would like to use Shift-Space as ESC, any suggestions?
[email protected], January 22, 2003 3:24
If you just want the caps lock key to be a second escape key then see my comment on https://www.vim8.org/tip_view.php?tip_id=166
If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to [email protected] after searching the archive. Help Bram help Uganda.
SourceForge Logo