inputrc中绑定meta没有效果,macosx

Binding meta in inputrc has no effect, macosx

我正在尝试通过在我的 inputrc 中为元键添加绑定来扩展 readline。我正在使用终端 (OSX)

理想情况下我想添加 "\M-h": "\C-w"

但是,我似乎无法绑定任何元键。我在终端中有选项,它将我的选项键视为元。结果我可以输入 M-b 就好了。在我的 inputrc 中绑定它不起作用。

我尝试使用 sed -nl 来记录发送到我的终端的转义序列。按 M-x 输出 ^[h,但是像 "^[h":"\C-w" 这样的绑定不起作用。非常感谢您的帮助。

编辑: 这是 readline 文档中的 sample file,它显示了如何根据发送的 ansi 转义键进行绑定。也许我没有映射到发送的正确转义键,有没有比使用 sed 更好的检查方法?

这是正确的绑定方式吗?不应该是 keyname:function-name 吗?虽然没抢到。

来自手册页:

   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.

您也可以考虑查看 /etc/inputrc,它具有默认绑定。

我的问题的解决方案是以下绑定:"\eh": "\C-w"

\e是readline对Esc键的映射

在没有元键的键盘上没有统一的表示方式。结果:

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

因此,终端将 Meta 视为选项,然后将 Esc 发送到 readline。