无法像使用 CTRL-r 一样转发搜索 Bash 历史记录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/791765/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 18:08:06  来源:igfitidea点击:

Unable to forward search Bash history similarly as with CTRL-r

bashsearch

提问by Léo Léopold Hertz ??

I am trying to search my bash history similarly as with CTRL-r, but to forward direction.

我正在尝试与CTRL-类似地搜索我的 bash 历史记录r,但要向前。

It has been a pain for me, when I just hit once too often CTRL-r, to find the previous command again.

对我来说很痛苦,当我经常点击一次CTRL- 时r,再次找到上一个命令。

How can you forward search your Bash history similarly as in reverse searching?

如何像反向搜索一样向前搜索 Bash 历史记录?

回答by hlovdal

You can search forward as well. From the bash info manual, "8.2.5 Searching for Commands in the History":

您也可以向前搜索。来自 bash 信息手册,“ 8.2.5 在历史记录中搜索命令”:

To search backward in the history for a particular string, type C-r. Typing C-ssearches forward through the history.

要在历史记录中向后搜索特定字符串,请键入C-r。键入C-s在历史中向前搜索。

The problem with Ctrl-S however is that sometimes collides with XON/XOFF flow control (in Konsole for instance). The searching is a readline feature however, and you should be able to bind it to some other key. Update: Simpler and better is just to disable XON/XOFF by running

然而,Ctrl-S 的问题是有时会与 XON/XOFF 流控制发生冲突(例如在 Konsole 中)。然而,搜索是一个 readline 功能,您应该能够将它绑定到其他一些键。更新:更简单更好的是通过运行来禁用 XON/XOFF

stty -ixon

回答by Eric Burghard

The best trick IMHO is enabling with pgupand pgdown. just put that in your ~/.inputrc

恕我直言,最好的技巧是使用pgup和启用pgdown。把它放在你的~/.inputrc

"\e[5~": history-search-forward
"\e[6~": history-search-backward

logout/login, type the first letters and then pgupor pgdownto search throughout history

注销/登录,输入第一个字母,然后pguppgdown搜索整个历史

ctrl-Rsearch all lines containing words, whereas history-search-forward search lines beginning with words

ctrl-R搜索所有包含单词的行,而 history-search-forward 搜索以单词开头的行

回答by Martin Dvorak

You may want to try https://github.com/dvorka/hstrwhich allows for "suggest box style" filtering of Bash history with (optional) metrics based ordering i.e. it is much more efficient and faster in both forward and backward directions:

您可能想尝试https://github.com/dvorka/hstr,它允许使用基于(可选)指标的排序对 Bash 历史进行“建议框样式”过滤,即它在向前和向后方向上都更加高效和快速:

enter image description here

在此处输入图片说明

It can be easily boundto Ctrl-rand/or Ctrl-s

它可以很容易地绑定Ctrl-r和/或Ctrl-s

回答by Eyad Ebrahim

I usually press ESCin terminal, and then the >. It resets at least and then you could try click less too often CTRL+R.

我通常按​​下ESC终端,然后按下>. 它至少会重置,然后您可以尝试减少点击次数CTRL+ R