【问题标题】:How to provide arguments to Readline functions via inputrc如何通过 inputrc 向 Readline 函数提供参数
【发布时间】:2021-05-14 13:41:21
【问题描述】:

我正在尝试使用 readline 提供的 insert-comment 函数来取消注释一行。
根据documentation

如果提供了数字参数,则此命令用作切换:如果行首的字符与 comment-begin 的值不匹配,则插入该值,否则删除 comment-begin 中的字符从行首开始

我的.inputrc 中有以下行:

"\eW": insert-comment 1

insert-comment 映射到 Alt-W (仅用于测试。我打算重新映射 Alt-# kbd> 当它工作时)

在重新加载.inputrc 时,在终端上输入一些文本(如#123),然后按Alt-W# 将被添加到任何我类型(如##123),与Alt-#的行为相同。

如何使用insert-comment 函数作为映射到自定义键序列的切换?

【问题讨论】:

    标签: bash readline


    【解决方案1】:

    据我所知,Readline 不支持在这样的绑定中添加参数。不过,您可以定义一个宏。例如,假设您将 insert-comment 绑定到 Alt-W。然后你可以定义 Alt-# 为

    "\e#": "\e1\eW"
    

    \e1 将参数设置为 1,然后 \eW 使用当前参数调用 insert-comment

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-21
      • 2013-07-15
      • 1970-01-01
      • 2020-04-05
      相关资源
      最近更新 更多