1

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?

cdosborn
  • 3,111
  • 29
  • 30

2 Answers2

1

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.

Community
  • 1
  • 1
cdosborn
  • 3,111
  • 29
  • 30
0

Is that the correct way to bind it ? Shouldn't it be keyname:function-name ? Didn't loot it through though .

From the man pages:

   Readline Key Bindings
   The syntax for controlling key bindings in the inputrc file is simple.  All that is required is the name of the command or the text of a macro and a key sequence to which
   it should be bound. The name may be specified in one of two ways: as a symbolic key name, possibly with Meta- or Control- prefixes, or as a key sequence.

   When using the form keyname:function-name or macro, keyname is the name of a key spelled out in English.  For example:

          Control-u: universal-argument
          Meta-Rubout: backward-kill-word
          Control-o: "> output"

   In the above example, C-u is bound to the function universal-argument, M-DEL is bound to the function backward-kill-word, and C-o is bound to run the macro  expressed  on
   the right hand side (that is, to insert the text \u2018\u2018> output\u2019\u2019 into the line).

   In  the  second  form,  "keyseq":function-name or macro, keyseq differs from keyname above in that strings denoting an entire key sequence may be specified by placing the
   sequence within double quotes.  Some GNU Emacs style key escapes can be used, as in the following example, but the symbolic character names are not recognized.

          "\C-u": universal-argument
          "\C-x\C-r": re-read-init-file
          "\e[11~": "Function Key 1"

   In this example, C-u is again bound to the function universal-argument.  C-x C-r is bound to the function re-read-init-file, and ESC [ 1 1 ~ is bound to insert  the  text
   \u2018\u2018Function Key 1\u2019\u2019.

Also you might consider looking into /etc/inputrc, it has the default bindings present.

baky
  • 631
  • 1
  • 8
  • 17
  • I believe it is. Here is a [sample file](http://cnswww.cns.cwru.edu/php/chet/readline/rluserman.html#SEC12) from readline docs. – cdosborn Mar 19 '15 at 16:19