🖥

#Ruby の pry で コマンド履歴を検索して戻る/進むショートカット ( reverse-i-search / i-search )

2020/03/22に公開

reverse-i-search

  • Ctrl + R で pryのコマンド履歴を検索できる
  • 検索中にもういちど Ctrl + R を押すと、検索結果をひとつずつ過去に戻れる
  • だがしかし、いちど戻ると、そこから逆に進む方法が分からない
  • 戻ってから進む方法が分からずに、たまに調べては諦め、そして5年が過ぎた

image
image

解決は .inputrc

~/.inputrc に以下を設定する

"\C-t": forward-search-history
  • pryの設定ではなく、実行するシェルの設定
  • .bash_profile とか .bashrc とか .zshrc とかと同じ扱い
  • 設定したらpryを終了、再起動する

動作確認

履歴を戻りすぎた場合に Ctrl+T で進めるようになったぞ!

image
image
image

原因

readline のデフォルトのキーバインドか何かと干渉していたのかもしれない。

image

command line - readline reverse-search-history C-r repeatedly finds next cmd, how to go back to previous? - Super User

Original by Github issue

https://github.com/YumaInaura/YumaInaura/issues/3042

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

https://line.me/ti/g2/eEPltQ6Tzh3pYAZV8JXKZqc7PJ6L0rpm573dcQ

Twitter

https://twitter.com/YumaInaura

公開日時

2020-03-22

Discussion