In Emacs
, I want to bind a particular key combination to a command. However, because I am using Emacs
in terminal mode within iTerm2
on OS X, I need to translate the key combo to character escape sequence and register that sequence with iTerm2
so that it will recognize the key combination.
But how do I find out the corresponding sequence given a key combination? For example, I found that something like ^[[1;8A
corresponds to Ctrl+Alt+up (where I have configured Alt to function as +Esc
in iTerm2
), but I have no idea how that key combination translates into this particular sequence.
Is there a way to look up or work out the escape sequence for any given key combo? For example, what is the sequence for Ctrl+Alt+r?
A related question, can someone explain to me the relationship between setting up a key combo with its corresponding sequence in iTerm2
and making Emacs
translate a sequence into its internal key representation using input-decode-map
inside .emacs
(e.g. (define-key input-decode-map "[escape_sequencehere]" [internal_key_representation_here]
)? It seems to me that setting it up in iTerm2
alone is sufficient to make the binding work in Emacs
, so when and why do we need to set up the latter in .emacs
? (and perhaps when do we need both to make something work?)
Some of the key combinations are sent directly to the application running in iTerm2
. You can get it
by using ctrl
+v
approach (see In bash, how do I bind a function key to a command?) or
bash-3.2$ ^[[1;10A (in this case I hit ctrl + v before shift+alt+up)
sed -n l
(note it's lowercase L
). For instance, you can see what the application receives if you send (shift
+alt
+up
):
bash-3.2$ sed -n l
^[[1;10A
\033[1;10A$
If some key combination does not get through, you can instruct iTerm2
to let it pass and map it to a key combination that you can detect as described above.
For instance, you can send through and map ctrl
+alt
+cmd
+R
to ESC+sdf
and your terminal will receive ^[sdf
which you can assign to a command in Emacs.
In your terminal type showkey -a
and let the key-strokes fly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With