Bash – bash’s meta key

bashkeyboard shortcutsxterm

I tried to use xmodmap to map META_L to the MENU key but it doesn't seem to be accepted by bash as the meta key. So, I am wondering how these components (keyboard, X, xterm, bash) relate to each in regard the the Meta- and Super-Keys. Any explanation would be appreciated.

Let me put this another way. The bash man page says, for example, that the function yank-nth-arg is bound to M-C-y and it works when I press Esc-Control-y. But I find this a bit cumbersome. So how can I make bash accept another key as Meta (like the Menu) for all its default bindings?

Best Answer

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.

Related Question