LoginSignup
10
10

More than 5 years have passed since last update.

zshのcontrol-rの過去コマンド検索でglobを使う

Posted at

結論

以下を.zshrcに追加すればおk

zle -la history-incremental-pattern-search-backward && bindkey "^r" history-incremental-pattern-search-backward
zle -la history-incremental-pattern-search-forward  && bindkey "^s" history-incremental-pattern-search-forward

解説

何も設定していないzshでcontrol-rを押すとhistory-incremental-search-backwardというwidgetが発動します。これはglobが使えません。で、これとは別にhistory-incremental-pattern-search-backwardというwidgetが存在し、これはglobが使えます。と言うわけでcontrol-rにhistory-incremental-pattern-search-backwardをバインドするのが↑の設定です。あとcontrol-sで逆向きに検索出来るようにします。

で、history-incremental-pattern-search-backwardはzsh v4.3.9から追加されていて、それ以前のzshを使ってる場合そのままだと死ぬので、history-incremental-pattern-search-backwardがある時だけ設定してます(zle -la ~~ &&のところ)。そんな古い環境とは縁のない人はここ書かなくていいです。

globが使えると普通のファイル名展開と同じく?(任意の一文字)、*(長さ0以上の任意の文字列)とかが使えるようになるわけです。あとデフォルトのglobと違って^が行の先頭の意味で使えたりします。

10
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
10