14 November 2007

RFC: vi, the Esc key, and Ctrl-[

As many of you probably know, the vi editor has two main modes, and switching back to command mode requires sending the Escape character. This can be achieved either by using the Esc key (the top left key on most keyboards) or by using CTRL-[. The latter has the advantage that the [ key is much closer to the home row than the Esc key, and is thus faster to type. Despite that, pretty much all the vi users I know still use Esc, and I wonder why. I've heard that on some keyboard layouts (like the French azerty), CTRL-[ is actually impossible to type, but in my experience many Free Software people (like me) use the US layout even though it's not their local layout.

So if you have a few seconds, I'd appreciate your feedback (via a comment on this post, or an email). You have the following options:

  • #1: vi (or a derivative like vim) is my main editor, and I use CTRL-[.
  • #2: vi (or a derivative like vim) is my main editor but I use the Esc key even though CTRL-[ is easy to type on my layout.
  • #3: vi (or a derivative like vim) is my main editor but CTRL-[ is too hard to type on my layout.
  • #4: I use another editor as my main editor.
  • #5: I have no idea what you're talking about, but I wish to state that I will vote for helix in the 2008 DPL elections.
Thanks!

71 comments:

Romain Francoise said...

OK so to get the ball rolling, my own answer is choice #4: I don't use vi(m) as my main editor. But when I have to use it, I use the Esc key out of habit, even though CTRL-[ is easy to type.

jamessan said...

I use Vim on a daily basis and still use Esc. I use a modified US layout though, where Esc is easily accessibly by my thumb. I've also moved ctrl to the capslock key where it rightly should be. :)

Anonymous said...

I vote #3...Ctrl-[ would require Ctrl-AltGr-8 which means all fingers will leave home row (as opposed to left hand leaving home row with Esc)

Anonymous said...

#3 for me.

I've always wondered why softwares were talking about this "CTRL-[" :-)

Chris C said...

#2. Having to use a modifier key to enable the single most common operation is madness.

Furthermore, Esc (with its clear half-inch gap from every other key) is the most difficult key to accidentally miss on the whole keyboard. When you're hitting it every other action, even a low miss rate can mean wasted time correcting mistakes.

- Chris

gillesMo said...

#3: like every french using their native layout.
That's also a reason I don't use evolution (next unread = Ctrl-]).

Anonymous said...

#3: I'm using the Finnish layout (as does every other Finn I can think of, except those who use dvorak) and the aforementioned Ctrl-AltGr-8 seems a little unnatural.

Anonymous said...

Just map ESC to CapsLock.

mentor said...

#5!

I use Ctrl-[, but my hypothalamus isn't completely retrained yet.

Evgeni Golov said...

Well, german layout here, so Ctrl+[ is Ctrl+AltGr+8 (as on other european layouts too) and thus I'm using Esc.
But I would vote #4, vi is not my favorite editor.

Javi said...

I use ESC, but I'll map it to CapsLock as said at other comment. It's a good idea, I think

Laurent C. said...

Choice #2 : I use always ESC key even tough CTRL-[ is easy to type on my US layout.

Another RFC for vim users : ":wq", ":x" or SHIFT zz ? ;)

Joachim Breitner said...

#3 as well, German keyboard layout...

Mikael Eriksson said...

I use vim as my main editor and I use Ctrl-C which is much easier to type than Esc or Ctrl-[.

Anonymous said...

#3 Using swedish layout. Esc is ONE keystroke, and thus much faster and less errorprone.

Gheesh said...

#3 for mee too (Spanish layout w/ AltGr)
ESC key is quite easy to get at, anyway.

Dean said...

#2, like Chris C said, hitting esc on a standard keyboard is really easy, and hence super fast.

tedp said...

#2: Vim & Esc (and ^[ is relatively easy to type). I don't like the idea of having to hit a key combination to switch modes all the time, Esc is fast and easy, especially because I've developed a non-standard way of touch typing.

tosh54 said...

i use a german keyboard and ctrl-[ is hard to type so i just map ESC to CapsLock.

Anonymous said...

#1 (vi with Ctrl-[).

At some point in my youth I had to use a Unix vendor proprietary keyboard (I think it was DEC) where the key that on PC keyboards is "Esc" on this keyboard generated some long series of VT command characters (I think it was supposed to be "Delete" or some such thing). Pressing that key would permanently delete something like 8 lines of data in vi (plain Unix vi, with only one command of undo), so I learned pretty quickly to stay the hell away from it. Ctrl-[ behaved exactly the same way on all of the various machines.

Today I mostly use laptop keyboards, where Esc is packed in closely with other keys, and it tends to move around the keyboard from one vendor to the next (e.g. on some Toshiba keyboards it has swapped places with "`", and I have used one oddball keyboard where "Esc" was on the right side of the keyboard next to keys like Del and SysRq).

The "big target on the corner of the keyboard" argument doesn't work at all on most laptop keyboards--Esc is a tiny key (sometimes up to 50% smaller than adjacent keys) next to several other keys, and it is located the maximum distance away from home row. It's about the hardest key to reliably hit on the left side of the keyboard. Thank goodness vi doesn't use SysRq or Pause as a mode switch key--those are about the only keys worse than Esc, and there's even more variation in their position on keyboards.

Ctrl and [] are so important to most of the stuff I do with a keyboard that I'm unable to use a keyboard productively without being able to reliably find these keys. I can go for weeks at a time without pressing Esc.

Anonymous said...

One gotcha for people who use multiple different flavors of vi:

Does "w!q" (or ":x!") mean:

"try really hard to write the file, and if you can't, quit", or

"try really hard to write the file, and if you can't, don't quit"?

I found out the hard way that different vi's answer this question different ways. The first is like ":w!" followed by ":q!" while the second is like ":w!" followed by ":q"...a huge difference if vi fails to save your modified file!

Matthew Johnson said...

Well, I hadn't thought about using ^], but on reflection I shall keep using esc. Reasoning being: ^] either means moving both hands, or one uncomfortably, whereas esc is easy to hit.

A couple of caveats, with my new laptop it's easy to miss and hit f1, which opens the vim help, and is hence annoying, and I haven't tried on my main keyboard at work, which is dvorak, where the ] is a little easier to get to (the laptop is awkward to rearrange). I think the best solution is remapping something in an easier to reach to exit mode in vim (such as caps or something next to space). Definitely a single key though.

KiBi said...

#3 because of macintosh/fr (Ctrl+Shift+Alt+5 opposed to a reachable Esc — i.e. my fingers are long enough so that I can reach it without moving my hand).

#4 too since I equally use vim & emacs (for different tasks).

#5 finally because helix just rocks!

eolo999 said...

Almost all europeans use ESC.
My is my favourite editor! Yep!

Dedalus said...

#1

I'm a French guy but I use Dvorak-US layout :P

pabs said...

I vote #4, nay, #5!

Anonymous said...

#1

Julien said...

#3 I'm french and ctrl+alt gr+8 it's horrible.

Gunnar said...

I use other editors, thank GNU!

Anonymous said...

This is vote 3 for the unlisted choice #6: map ESC to CapsLock.

I do not like Ctrl on CapsLock because it makes the position of the Ctrl keys nonsymmetrical.

Anonymous said...

I choose #3. But that's a subjective view. For me it's easier (also to remember and to associate the ESC-key with "ending"). In fact the ESC key is just one key the CTRL-[ variant requires me to press three.

So I choose #3.

Greetings,
Drizzt

Thep said...

#2: While I know ^[ is easier to type, pressing Esc has become my "finger habit". I even adjusted myself from weird Esc position on VT100 keyboard (which was about F10 key position). And I don't map CapsLock to Esc because I already map it to Ctrl.

Anyway, I heard people saying about ^[ easiness from time to time. And I feel like to try it as well.

Anonymous said...

Canadian french keyboard is an excellent alternative to the azerty hell…

Anonymous said...

#3 - French Layout

Daniel said...

I'm using vi with the ESC-key. Pressing Ctrl-[ would require movement with both hands and the escape key obviously not. The only downside to this is... sun keyboards with the help key as the upmost left key which is annoying, but with the sun unix keyboard layout (ctrl and capslock switched) typing ctrl-[ whould be even easier than on a keyboard with pc layout. The ESC key is moved one row down on the unix layout so even that would be easier than on a pc layout. So the sun unix keyboards are the most Vi friendly keyboards... maybe that has something to do with bill joy?

http://www.pfu.fujitsu.com/hhkeyboard/kb_collection/

Anonymous said...

#3, German layout.

Remapping Esc to some other key is not an option since this would seriously confuse me when working at other computers than my private laptop.

kluge said...

Another vote to the unlisted option: Map Esc to Caps Lock.

If I hadn't done that, I'd choose #3, because Ctrl-[ is hard to hit on Finnish layout. Although on my laptop Esc is too hard to hit and I'd probably map Ctrl-S to Ctrl-[.

Anonymous said...

I agree with Chris C; Fitt's Law applies here, making Esc quite easy to hit reliably. I also find Esc easier on a laptop keyboard, because my fingers have less distance to travel, and I've never worked on a laptop that had Esc somewhere other than the top left. (I've seen other keys in freakish locations, notably ~` in the upper right next to scroll lock and the other keys they figured people never used; on that system I actually found it faster to type $HOME and $(...).)

So, for myself, #3 (I use Escape when I use vim) and #4 (I also use Emacs).

Actually, I wonder: do any Emacs users use C-[ for Meta, rather than using alt or another modifier key?

Meike said...

German layout, regular vi user, option #3

Neil Williams said...

Option 3 only - Esc only and only vim. I've never used anything else and see no need to do so.

Raphael Hertzog said...

#3 as well, French layout

Adeodato Simó said...

I use Vim, and I use Ctrl-C to go back to Normal mode. This is no custom mapping, works out of the box (see :help i_CTRL-C).

The semantics are a bit different (abbreviations are not expanded), so I ended up with "inoremap [C-c] [Esc][Esc]".

Spanish keybord, where Ctrl+] is hell. (In fact, I wouldn't be using vim if I wasn't using Ctrl-C.)

arno. said...

I use Ctrl-C also. I find Ctrl-] or Escape too far to reach for something I do hundreds times in a day :)

Steve said...

I use ESC on this laptop, and all other machihes, primarily because the Esc is hard to miss.

I guess that just comes down to practise.

Steve

Damien said...

#3 : vim is one of my mains editors, but I actually use a french azerty keyboard.
(I don't know if I'd use ctrl+[ if I had a qwerty keyboard)

gillesMo : now in evolution the space bar may be used to go to the next unread item.

Wawrzyniec Niewodniczański said...

#1 but nice to hear about other ways - I have to try.

Wawrzyniec Niewodniczański said...

Sorry it should be #2, but nice to hear about something else than Esc, which is quite annoying on my laptop Quite often I hit F1 rather Esc and start help.

arne said...

#2: I prefer typing 1 key (ESC) instead of two (ctrl-[) AND because [ is hard to type.

(qwerty keyboard.)

Bruno Lomax said...

#2: vi (or a derivative like vim) is my main editor but I use the Esc key even though CTRL-[ is easy to type on my layout.

lerouge said...

#3 (french layout)

curson said...

I use vim and I use Esc to switch mode. Actually, on my Italian keyboard layout, Ctrl-[ is almost impossible, 'cause to have the "[" you're required to go for an Alt-è.

Jason said...

#2 for me... but only because I didn't know about CTRL-[

(I'll try to use CTRL-[ in future, but it might take a while to break the ESC-key muscle memory)

Anonymous said...

Vim is my main editor. I find Caps Lock completely useless, so I am using xmodmap to map Escape to it ;).

CLAIRE D'ETE said...

Well, again I have no idea what you guys (and gals?) are going on about, I never use ESC except in very old games like simcity, but if #5 refers to the Helix wind turbine, I think it's genius and will even be using the page you gave the link for with my electrotecnhics class, so thanx mate.

Marius said...

#2. I never learned to properly touch-type, so the proximity to the home row isn't that important to me, and I'm used to finding Esc.

For a while I also used to hit F1, which on a Thinkpad keyboard occupies the proper place of Esc. I remapped <F1> to <Nop> until I got used to it.

Laurent: I started using ZZ instead of :wq once I learned about it.

Gerfried said...

vim all the way - hell, even now I type in vim through the great itsalltext firefox/iceweasel extension.

Said that, I'm using German keyboard layout, so ctrl-[ is extremely uncomfortable here. But having looked up ctrl-[ I guess I'll settle with ctrl-c which I found out through reading up on the help.

Thanks for showing me ctrl-c, it's much more natural and even intuitive if you think about it *gg*

Anonymous said...

Option 3

Mark said...

Option 6.5: Re-map the little-used caps lock to esc:
http://haller.ws/logs/view.cgi/VimXmodmap

Anonymous said...

I don't touch-type so the "distance to homerow" metric never bothers me, so i guess I'm with #2.

I think i'll use "esc" anyway, because I also like to hit "enter" quite theatrically, adds some structure to the typing poetry ;) I don't switch contexts (or was it "modes" ?) so often, so Esc is a nice counter-point and a good target on the keyboard, so maybe that's a different reason why people use it.

Anonymous said...

#1

I discoverd Ctrl-[ many years ago and never looked back.

Andreas Metzler said...

#3 German keyboard, mostly typing one handed anyway. (I do not think that fast ;-)

Anonymous said...

#7: ctrl+o, ctrl+l :^)

metrics said...

#1: With Ctrl mapped to Caps Lock.

Romain Francoise said...

Thanks for the feedback, everyone! For those of you following along via the Comments feed: I summarized the answers in a new post, be sure to check it out!

bartman said...

I use vim all the time. I am somewhere between #1 and #2. My ESC key is to the left of the [1] key, so it's actually comfortable to hit with the left pinky finger.

Wouter Verhelst said...

I use vim quite often. My current keymap requires three keys just to type [, so I guess you got the picture -- [esc] is just so much faster. Besides, given my large hands and this apple keyboard, it's not even out of reach, anyway.

florin said...

I use vim, but I remapped CapsLock to ESC.

Lloeki said...

#3. French.

Now someone mentioned ^C instead of ^], and it seems to work fair enough.

Note that telnet uses ^] as its escape sequence too, but (as opposed to vim) it works by just pressing AltGr+]. Go figure.

I'd use US (maybe even dvorak) layout if I hadn't had a laptop (and putting stickers on the keys is quickly getting ugly if you type 8 hr/day).

Romain Francoise said...

Lloeki: It's CTRL-[, not CTRL-].

postlogic said...

#3, norwegian

Anonymous said...

I mapped my escape key to CAPS LOCK because I don't use that one anyway, and it's really close to the front row...

Once upon a time when Vi was first made, I heard the escape must have been closer to the home row, perhaps where tab now is...