Jonathan Tran on 20 Dec 2009 12:57:16 -0800


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

iTerm key bindings - switching Control and Command

  • From: Jonathan Tran <jonnytran@gmail.com>
  • To: Philly Lambda <philly-lambda@googlegroups.com>
  • Subject: iTerm key bindings - switching Control and Command
  • Date: Sun, 20 Dec 2009 12:57:02 -0800 (PST)
  • Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=beta; h=domainkey-signature:received:x-beenthere:received:received:received :received:received-spf:received:mime-version:received:date:x-ip :user-agent:x-http-useragent:message-id:subject:from:to :x-original-authentication-results:x-original-sender:reply-to :precedence:mailing-list:list-id:list-post:list-help:list-archive :x-thread-url:x-message-url:sender:list-unsubscribe:list-subscribe :content-type; bh=S0wb1yJIyHDMPug8c1cVrY22Gu5Ea3HLEucLU1WZTgc=; b=Z5HzCsQeibxkKqm1+ThSinGhoBz0JzUH1uKhELNFn46qrA2J8fIGPWy0TclAON3xbu 10nd3Sa6jHNGdvDrh7MvwL5dPDcwRY5dvIjukICKutWPYJPP4O2m93Em8rKg36l5MpEB WRAHzlwuiPz5khSrprsc9UR55godJcIbbm+Ck=
  • List-archive: <http://groups.google.com/group/philly-lambda?hl=>
  • Mailing-list: list philly-lambda@googlegroups.com; contact philly-lambda+owners@googlegroups.com
  • Reply-to: philly-lambda@googlegroups.com
  • Sender: philly-lambda@googlegroups.com
  • User-agent: G2/1.0

A while back, Philip showed us how to move the control modifier in
Emacs to the command key on Mac [1] to allow us to comfortably use our
thumbs on the command key, instead of our pinkies, w/o disturbing all
the command-shortcuts of other Mac apps.  I started developing more on
my Mac recently, so I ended up spending a while figuring out how to do
the same thing for iTerm.  Thought others might be interested... I
found this to be essential on my MacBook due to its tiny Control key
in the worst possible spot.

Go to Bookmarks, Manage Profiles.  In your keyboard profile (probably
Global), add a new mapping for each key that you care about.  Since I
was making all the Control-<blah> keys work by pressing Command-
<blah>, I added mappings like this.

Note: the (!) means you need to check the High Interception Priority
checkbox to override the normal Command-shortcuts.

Key Combination | Action
cmd-hex code 0x61 | send hex code 1 (!)
cmd-hex code 0x62 | send hex code 2 (!)
cmd-hex code 0x63 | send hex code 3 (!)
cmd-hex code 0x64 | send hex code 4 (!)

... and so on, all the way up to 0x7a.  (I decided to omit some so
that Command-T still makes a new tab, for example.)  The first number
corresponds to the hex ascii code of the key you are typing.  The
second number is what to do when someone presses that key.  Through
trial and error (I couldn't find documentation on any of this...) I
discovered that sending hex code n is equivalent to Control-<n +
0x60>.

The only thing I really miss that this doesn't handle, is undo
(Control-/).  Since the hex code of / (0x2f) is less than 0x60, the
above trick of subtracting 0x60 doesn't work.  (Same thing w/ Control-
_.)  So as a workaround, I ended up creating a new key binding to undo
that could easily be mapped to in iTerm.

In my .bashrc, I added this line, which binds Control-{ (a key
combination I don't use on the command-line) to undo:
bind "\C-{":undo

Then in iTerm I added a mapping like this:
cmd-/ | send hex code 1B (!)

...Note: you have to enter it as hex code 0x2f.  It then shows up as
"cmd-/".  Be careful, though, b/c an apparent bug in iTerm converts it
to "cmd-num-/" if you modify it.

[1] http://groups.google.com/group/philly-lambda/browse_thread/thread/f95ffffeb875d8fd/