如何使用反向i-搜尋指令(ctrl+r)向前搜尋紀錄?

如何使用反向i-搜尋指令(ctrl+r)向前搜尋紀錄?

在readline手冊中

# man readline

以下介紹如何向後和向前搜尋。

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.

當我按下 ctrl+r 並輸入「apt-get」時,我可以透過連續點擊 ctrl+r 來執行反向搜尋記錄。但當我點擊 ctrl+s 時,終端機沒有繼續前進。我做錯了什麼嗎?

另外,元前綴“M-”代表什麼鍵?

答案1

該序列C-s取自終端驅動程序,如您所見

stty -a | grep '\^S'

若要釋放序列以供 readline 使用,請將停止終端序列設為其他序列,例如

stty stop ^J

或將其完全刪除

stty stop undef

之後C-s將在給定的終端中工作。

設置它~/.bashrc以使其在每個終端上都能工作。

正如已經指出的,順序M-意味著關鍵。Alt

答案2

除了按照上面的建議分配不同的 TTY“停止”字元之外,如果您不打算使用它(我傾向於不這樣做),您還可以將其完全刪除,如下所示:

$ stty stop undef

然後 readline 可以使用 control-s 進行向前搜索,並且由於添加了新的停止字符,您不會得到任何奇怪的行為。

答案3

正向搜尋記錄 (Cs) 不起作用(儘管它在手冊頁中)。

“M-”代表 Alt 鍵修飾符。

答案4

請不要使用:

stty stop ^J

stty stop ^P

或其他任何東西,就像^Jssh 造成大問題一樣。 (無論如何,我不知道為什麼。)登入後Enter,反斜線不起作用。或者我必須輸入:

stty sane 
export TERM=linux

在我想打字之前

ssh root@192...

所以

stty stop ^P

同時解決了這兩個問題。

相關內容