Bashでリバース検索履歴を再バインドします。

Bashでリバース検索履歴を再バインドします。

reverse-search-historyデフォルトでは Cr にバインドされます。 Cr を入力して検索を開始し、Cr を再入力して前の一致に移動できます。

私はreverse-search-history\ er(Alt-r)で囲みました。この新しいバインディングは初期検索には機能しますが、Alt-rを押しても検索は続行されません。 Crはまだ逆方向検索を繰り返す必要があるようです。

Alt-rを繰り返し機能に使用する方法はありますか?それとも、「継続検索」機能を主キー以外のキーにバインドする方法はありますか? emacsではこれを行うことができますが、bash / readlineに関する関連ドキュメントは見つかりません。

ベストアンサー1

いくつかのテストを経て、次のような答えを得ました。

存在するLinux仮想コンソール、"Alt-R"はshowkey -a"Esc"と"r"の"^[r"を生成し、Escapeは検索文字列を削除して後方検索を停止します。

存在するxterm\M-r、「ò」と表示されます。

]# bind -p |grep ' reverse-se'
"\C-r": reverse-search-history
"\e[172": reverse-search-history
"\e[1;3A": reverse-search-history
"ò": reverse-search-history

説明したように、「\ e ...」は部分的にのみ機能します(修正された上向き矢印です)。


man bash実際にはいくつかの情報があります。

   convert-meta (On)
          If set to On, readline will convert characters with the eighth bit set to an
          ASCII key sequence by stripping the eighth bit and prefixing an escape char-
          acter (in effect, using escape as the meta prefix).  The default is On,  but
          readline will set it to Off if the locale contains eight-bit characters.

以下はreadline変数です:

isearch-terminators
    ... If this variable has not been given a value,
    the characters ESC and C-J will terminate an incremental search.

おすすめ記事