In GNU readline manual, it says the left Alt is usually Meta:

The Meta key is labeled ALT on many keyboards. On keyboards with two keys labeled ALT (usually to either side of the space bar), the ALT on the left side is generally set to work as a Meta key.

But by experiment, I think the left Alt is actually ESC, rather than Meta. That's because, given the following inputrc configuration:

"\eB": vi-bWord

Pressing AltShiftb works as expected.

However if I change the key binding to the following:

"\M-B": vi-bWord

Pressing AltShiftb does nothing.

I'm wondering why Alt is actually ESC instead of Meta? How to change Alt to act as Meta key?

  • 2
    – muru
    Aug 14, 2019 at 10:13
  • Try in a shell started as INPUTRC=/dev/null LC_CTYPE=C bash --norc. I don't think that \M- works with utf-8 locales (haven't tried too much either, though ;-)).
    – user313992
    Aug 14, 2019 at 14:04
  • basically, readline should recognize ESC as a synonym for the meta-prefix. "\eB" and "\M-B" should be synonymous.
    – user313992
    Aug 14, 2019 at 14:17
  • @mosvy Just tried LC_CTYPE=C trick. This is interesting -- in UTF-8 locales, bind -p shows all \e ESC prefixed key bindings, while in C locale they are just \M- prefixed as advertised in the manual. Seems Meta has some other uses in non-C locales? Combining several clues presented to me, including the answer linked by @muru (which I do not understand 100%) and readline variables like input-meta, output-meta, convert-meta, I vaguely think Meta is not normally used because somehow \M- prefixed keys conflict with multi-byte characters??
    – Naitree
    Aug 14, 2019 at 14:38
  • You can ignore (for now) the high-bit/metaSendsEscape mess -- your terminal is clearly sending ESC when you press ALT (you can make that sure by running cat and pressing ALT-p: it should print ^[p). The problem is why "\eB" and "\M-B" are only considered synonymous in bindings when LC_CTYPE is C -- I haven't got an answer for that, yet.
    – user313992
    Aug 14, 2019 at 15:01


You must log in to answer this question.

Browse other questions tagged .