Previous: Emacs For Mac OS Wiki, Up: Emacs on Mac OS [Index]
iTerm Wiki for Emacs — Super and Hyper Keys
The reason for this has to do a lot with DEC terminal history and the keys that were available in some of the earliest possible terminals. The DEC terminal became the default basis of emulation for most software.
Contrast this with the Space-cadet keyboard that influenced the design of Emacs, made for MIT Lisp machines. It included several modifier keys which allowed multiple character sets as well as a large macro space for binding commands to key combinations. Two modifier keys to the left of the space bar on the Space-cadet keyboard include the Super and Hyper keys.
While insanely useful for the experienced user, fewer people worked on Lisp machines compared to the widespread availability of VT-series character terminals. All command line and serial-terminal interaction you’ll ever find supports VT-100.
In GUI mode most emacsen will bind the Windows or Option key to Super*U. Or if you’re a Mac user, you might have swapped *Alt and ⌘ so the Meta key is closest to the spacebar and easier to reach.
When you press a key on your keyboard your terminal emulator will send a character or an escape sequence down the connection. For DEC or xterm terminals, some keys may not send signals. iTerm2 can make use of any key that OSX will respond to and you can customize it to run commands locally, remotely or send signals down the terminal connection to the remote machine.
First, connect your remote machine and issue the cat command with no parameters. Depending on your OS, termcap on the remote and the codepage your keyboard is set to, you’ll see either a character or an escape sequence when you type something.
Let’s see how the Latin letter O
works when pressed with modifier keys.
o
, I get an o
.
ALT+o
, I get ^[o
CTRL+ALT+o
, I get ^[^O
SHIFT+ALT+o
, I get ^[O
These combos are being read by the remote machine and being fed to STDIN
to
cat
(and cat
is reading them back as output). They’re also the most basic
escape sequences, as ^
is the code for COMMAND
, and ^[
is for ALT/META
,
known as the escape sequence ^[
. For terminals and IBM PCs, the ^[
signifies some sort of terminal code, signifying a keypress or some action to
be taken on the terminal or the remote. If your keyboard has a D-pad, try
hitting <up> <down> <right>
and <left>
. Usually these will be ^[[A
,
^[[B
, ^[[C
and ^[[D
, respectively.
You can press C-c
to get out of cat
Now let’s try sending a more complicated escape sequence using some keys on your keyboard and fool Emacs on the remote into thinking you pressed a Hyper key combo.
Ctrl+⌘+Option+A
, which is the
three leftmost keys next to the space bar plus the letter A
.
^[[1;P9
, so let’s start off with that code.
^+Option+Control+a
Send Escape Sequence
[1;P9
(global-set-key (kbd "H-a") 'dired)
Ctrl+⌘+Option+A
, dired
should pop up. Proceed with
adding the rest of the keys and escape codes in your iTerm2 setup. Also,
you can use the cat
command to check your work and ensure that the proper
escape sequences are reaching the remote machine.
Control
and META
such as C-c H-o
with this technique. For C-c H-o
you would hit C-c
and then release the
keys, then Ctrl+⌘+Option+o
for the H-o
part.
Previous: Emacs For Mac OS Wiki, Up: Emacs on Mac OS [Index]