Showing posts with label esc. Show all posts
Showing posts with label esc. Show all posts

Thursday, April 10, 2008

Ways to Avoid the Esc Key

I've been running this into the ground, but reaching for the Esc key is inefficient on modern keyboard layouts. I've spent some time recently investigating ways to avoid reaching way the hell over to the top-left hand corner of the keyboard in an effort to maintain focus on the home row. I struck gold with a few of the ideas presented on this Vim tip. Here's my take on what works best.

1) Use Ctrl-[

This is what I've been doing until recently; although it's a bit awkward as far as key chords are concerned. It still beats the hell out of going all the way to Esc, and it's built right into Vi(m), so there aren't any fancy tricks required to make it work.

2) Use Ctrl-c

Another builtin key chord that will take you from insert to normal mode. Depending on your keyboard and personal preference, it may feel better than Ctrl-[.

3) Map a combo inside Vim

I've seen people suggest two combos that were particularly attractive from an efficiency standpoint.

map! ii <Esc> " map ii to Esc
map! ;; <Esc> " map ;; to Esc

With these, you're typing in insert mode, hit `;;' and you're back in normal mode. From a touch-typist point of view `ii' is particularly attractive but has the obvious downside of not allowing you to type a literal "ii" in your document without typing it twice.

4) Remap Caps lock

Caps lock is placed in a very convenient location and is very rarely used by most programmers. Reclaim this valuable real estate by mapping it to Esc as it was on the original HP 9000 ITF HIL keyboards. This is the approach I'm using right now, and I LOVE IT. Remapping the key on X Windows is done as follows.

a) Create a file in your home directory called .Xmodmap

# begin -------------
remove Lock = Caps_Lock
keysym Caps_Lock = Escape
# end ----------------

b) Create a reference to .Xmodmap in your .xinitrc

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

If you don't want to restart X, you can manually run
xmodmap ~/.Xmodmap after you create the first file.

5) Avoid shift-space Mapping

Quite a few people recommend mapping the shift-space key chord to Esc; however, many terminals can't differentiate between shift-space and regular ol' space. Gnome terminal is one of them, so if you run Linux, there's a good chance this mapping won't work for you.