我每次运行命令时都会按Ctrl R,但输入一个单词后(例如查找)我发现命令不在我的历史记录中,所以我按预期得到了这个:
(failed reverse-i-search)`find`: cat fire.txt
现在如何取消搜索,但在命令行中保持“查找”?无论什么键,我按’cat fire.txt’都会在我的命令行上结束,我必须擦除并重新输入我的命令.
我正在使用Ubuntu.谢谢.
我不知道你可以完全按照自己的意愿行事,但你可以隐约接近(尽管它牺牲了反向搜索的其他功能).
将键序列绑定到history-search-backward并通过键入起始单词然后按下绑定序列来进行搜索.
history-search-backward ()
Search backward through the history for the string of characters between the start of the current line and the point. The search string must match at the beginning of a history line. This is a non-incremental search. By default, this command is unbound.
但这仅适用于以您要搜索的单词开头的命令(以及不是增量的).
更新:刚刚发现,在寻找其他东西时,在bash NEWS for 4.3中有一个条目说
b. There are new bindable commands to search the history for the string of
characters between the beginning of the line and the point
(history-substring-search-forward, history-substring-search-backward)
因此,这意味着使用足够新的readline版本(即NEWS的readline部分),您仍然可以使用此版本进行子字符串历史记录搜索.