1

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

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

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

我尝试使用sed -nl来记录正在发送到我的终端的转义序列。按下M-xoutput ^[h,但是类似的绑定"^[h":"\C-w"不起作用。非常感谢您的帮助。

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

4

2 回答 2

1

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

\e是 readline 到 Esc 键的映射。

没有统一的方式来表示缺少它的键盘上的元键。因此:

Mac OS X 终端的“选项作为元键”选项仅表示 >“带有 ESC 的前缀” - Chris Page

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

于 2015-03-19T16:54:23.903 回答
0

这是绑定它的正确方法吗?不应该是 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,它具有默认绑定。

于 2015-03-19T12:14:05.280 回答