bashterminalreadlineansi-escapemeta-key

Binding meta in inputrc has no effect, macosx


I'm trying to extend readline, by adding a binding for the meta key in my inputrc. I'm using Terminal (OSX)

Ideally I'd like to add "\M-h": "\C-w"

However, I cannot seem to bind any meta key. I have the option in Terminal, which treats my option key as meta. As a result I can enter M-b just fine. Binding to it in my inputrc doesn't work.

I Tried using sed -nl to record what escape sequences were being sent to my terminal. Pressing M-x outputs ^[h, however a binding like "^[h":"\C-w" does not work. Help is much appreciated.

edit: Here is a sample file from the readline docs, which shows how to bind based on the ansi escape keys being sent. Perhaps I'm not mapping to the right escape keys being sent, is there a better way to check than with sed?


Solution

  • The solution to my question is the following binding: "\eh": "\C-w"

    \e is readline's mapping to the Esc key.

    There's not a uniform way of representing the meta key on keyboards lacking it. As a result:

    Mac OS X Terminal's "option as meta key" option only means >"prefix with ESC" - Chris Page

    So, Terminal treats Meta as Option which in turn sends Esc to readline.