The mapping of the
Alt key to
Escape (ASCII 033,
"\e") is done by your terminal emulator, the readline library (which handles the
~/.inputrc) has no part in it.
The problem is that there is no way to send the actual key events to a program running in a terminal; the terminal will convert them into sequences of bytes which the program can read from the tty.
For the Alt/Meta key, there are two ways to do it:
Map it to Escape (ASCII 033 / 0x1b) -- pressing
Alt-K will actually send
"\eK", etc. This is the default in most terminal emulators, but it's usually configurable and you have all the reasons to make it the default if it already isn't.
Turn on the high 7th bit on the ASCII value of the key -- pressing
Alt-K will actually send the
0x6b | 0x80 = 0xeb byte,
0x6b being the ASCII value of
It's the latter which is recognized as
"\M-k" in readline bindings.
And that does not work and is horribly broken with any multibyte locales like
en_US.UTF-8 (which are the default on most modern systems). On such system, the terminal emulator may not send the raw
0xeb byte (which is not a valid UTF-8 sequence, but binary garbage), but may convert it from ISO-8859-1 to UTF-8, resulting in the
"\xc3\xab" = "ë" (
e with diaeresis) being sent when
Alt-K is pressed.
But readline doesn't know how to map
"ë" back to
"\M-k" no matter how much you fiddle with the plethora of options like
And even if you could do it, that would still be broken, because people may actually want to type
"ó" and will not appreciate those being handled as unrelated keys like