如何使用 reverse-i-search 命令 (ctrl+r) 向前搜索历史?

use*_*637 12 command-line

在阅读手册中

# man readline
Run Code Online (Sandbox Code Playgroud)

下面介绍如何向后和向前搜索。

reverse-search-history (C-r)
Search backward starting at the current line and moving `up' through the history as necessary.  This is an incremental search.

forward-search-history (C-s)
Search forward starting at the current line and moving `down' through the  history  as  necessary.   This  is  an  incremental search.
Run Code Online (Sandbox Code Playgroud)

当我点击 ctrl+r 并输入“apt-get”时,我可以通过不断点击 ctrl+r 来进行反向搜索历史记录。但是然后我点击 ctrl+s 并且终端没有前进。我做错了什么吗?

还有 Meta 前缀“M-”代表什么键?

enz*_*tib 16

该序列C-s取自终端驱动程序,如您所见

stty -a | grep '\^S'
Run Code Online (Sandbox Code Playgroud)

要释放序列供 readline 使用,请将停止终端序列设置为其他序列,例如

stty stop ^J
Run Code Online (Sandbox Code Playgroud)

或完全删除它

stty stop undef
Run Code Online (Sandbox Code Playgroud)

之后C-s将在给定的终端中工作。

设置它~/.bashrc以使其在每个终端中工作。

M-序列是指Alt键,如前所述。