加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – 取消bash中的反向搜索失败,但保留我输入的内容

发布时间:2020-12-14 01:43:54 所属栏目:Linux 来源:网络整理
导读:我每次运行命令时都会按Ctrl R,但输入一个单词后(例如查找)我发现命令不在我的历史记录中,所以我按预期得到了这个: (failed reverse-i-search)`find`: cat fire.txt 现在如何取消搜索,但在命令行中保持“查找”?无论什么键,我按’cat fire.txt’都会在我的
我每次运行命令时都会按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部分),您仍然可以使用此版本进行子字符串历史记录搜索.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读