如何向 Readline 函数提供参数,例如glob-expand-word
默认绑定的参数C-x *
?
在本例中,我想提供一个数字参数,以便在光标之前的单词后附加一个星号。
man bash
:
全局扩展字 (Cx *)
point 之前的单词被视为路径名扩展的模式,并且插入匹配文件名的列表,替换该单词。如果提供数字参数,则在路径名扩展之前附加一个星号。
答案1
可以使用 向 Readline 函数提供数字参数M-0, M-1,...
,其中M--
以负数字参数开头。
此外,该universal-argument
函数(可选地绑定到C-u
)(见下文)还可以通过执行该函数然后按数字序列(可选地带有前导减号)来向命令提供数字参数:
"\C-u": universal-argument
man bash
(摘录):
Numeric Arguments
digit-argument (M-0, M-1, ..., M--)
Add this digit to the argument already accumulating, or start a new argument. M-- starts a negative argument.
universal-argument
This is another way to specify an argument. If this command is followed by one or more digits, optionally with a leading minus sign, those digits define the argument. If the command is followed by
digits, executing universal-argument again ends the numeric argument, but is otherwise ignored. As a special case, if this command is immediately followed by a character that is neither a digit nor
minus sign, the argument count for the next command is multiplied by four. The argument count is initially one, so executing this function the first time makes the argument count four, a second time
makes the argument count sixteen, and so on.