The mapping from keyboard keys to modifiers like Meta
and Control
is handled by the X server (i.e. the low-level part of the GUI). This mapping can be manipulated through the old-style xmodmap
command or the new-style XKB interface, or through a GUI configuration tools that uses one of these under the hood.
By default, on most setups, the Meta
key is the key labeled Alt. This is because historically, many unix workstations had a key labeled Meta where PCs have a key labeled Alt. So if you have a binding for M-C-y
, press Ctrl+Alt+Y.
To check what your current bindings are, start the xev
program in a terminal. With the xev window focused, press keys; you'll see a transcript of the generated events in the terminal.
The communication between terminal emulators (or terminal devices corresponding to a physical terminals) and applications uses characters. When you press A, the terminal receives the information “A
key, no modifier”, but what it sends to the application running in the terminal is the character a
. When you press a function key like Up or F1, there's no corresponding character; the terminal sends a character sequence beginning with the escape character (byte 27, sometimes written \e
or ^[
). When a terminal emulator such as xterm received a key press event with the Meta
modifier, it translates that key to an escape character followed by the key's underlying function, e.g. \ea
(escape, lowercase a) when you press Meta+A.
What is the exact difference between a 'terminal', a 'shell', a 'tty' and a 'console'? may be useful background.
terminfo is probably not going to help you much. In most terminal emulators, you can configure with M-x
sends <Esc>x
or x
with the 8th bit set, and the terminfo entry won't magically be updated when the user does so.
Also, most character sets are 8bits now, so it doesn't make much sense nowadays to use that 8th bit for Meta.
I would just hardcode M-x
== <Esc>x
(the sequence of two characters \033
and x
). This way, even if the terminal doesn't support that mode, the user can still type Esc, x in sequence.
Best Answer
This is the same question I asked I while back, so I'm not taking credit for this, but I had to put
in
.Xresources
to make Alt work as Meta in both xterm and urxvt. It is a bit contradictory, but it works. So experiment with those options. Also, I had to putin
.xinitrc
for it to work.Edit: My question: Emacs commands in xterm