如何通过 inputrc 为 Readline 函数提供参数
How to provide arguments to Readline functions via inputrc
我正在尝试使用 readline 提供的 insert-comment
函数取消注释行。
根据 documentation:
If a numeric argument is supplied, this command acts as a toggle: if the characters at the beginning of the line do not match the value of comment-begin, the value is inserted, otherwise the characters in comment-begin are deleted from the beginning of the line
我的 .inputrc
中有以下行:
"\eW": insert-comment 1
将 insert-comment
映射到 Alt-W(仅用于测试。我打算重新映射 Alt-# 有效时)
重新加载 .inputrc
时,在终端上输入一些文本(如 #123
),然后按 Alt-W、#
会添加到我输入的任何内容前面(如 ##123
),与 Alt-#[=40= 的行为相同].
如何使用 insert-comment
功能作为映射到自定义键序列的切换?
据我所知,Readline 不支持在这样的绑定中添加参数。不过,您可以定义一个宏。例如,假设您将 insert-comment
绑定到 Alt-W。然后您可以将 Alt-# 定义为
"\e#": "\e1\eW"
\e1
将参数设置为 1,然后 \eW
以使用当前参数调用 insert-comment
。
我正在尝试使用 readline 提供的 insert-comment
函数取消注释行。
根据 documentation:
If a numeric argument is supplied, this command acts as a toggle: if the characters at the beginning of the line do not match the value of comment-begin, the value is inserted, otherwise the characters in comment-begin are deleted from the beginning of the line
我的 .inputrc
中有以下行:
"\eW": insert-comment 1
将 insert-comment
映射到 Alt-W(仅用于测试。我打算重新映射 Alt-# 有效时)
重新加载 .inputrc
时,在终端上输入一些文本(如 #123
),然后按 Alt-W、#
会添加到我输入的任何内容前面(如 ##123
),与 Alt-#[=40= 的行为相同].
如何使用 insert-comment
功能作为映射到自定义键序列的切换?
据我所知,Readline 不支持在这样的绑定中添加参数。不过,您可以定义一个宏。例如,假设您将 insert-comment
绑定到 Alt-W。然后您可以将 Alt-# 定义为
"\e#": "\e1\eW"
\e1
将参数设置为 1,然后 \eW
以使用当前参数调用 insert-comment
。