LoginSignup
22
15

More than 5 years have passed since last update.

zshで適度なcase-insensitive補完

Posted at

zshで大文字小文字を無視して補完したい.
例えば次のような感じ.

~ % cd d[TAB]
Desktop/    Downloads/  deepdream/
Documents/  Dropbox/    dev/                                      

そのためには次のように.zshrcに書けば良いです.

  1. 大文字小文字を無視して補完する

    zstyle ':completion:*' matcher-list 'm:{[:lower:][:upper:]}={[:upper:][:lower:]}'
    
  2. わざわざ大文字を入力した時は小文字の候補を補完しない

    zstyle ':completion:*' matcher-list 'm:{[:lower:]}={[:upper:]}'
    
  3. でもやっぱり大文字の候補が見つからない場合には, 小文字の候補を補完する

    zstyle ':completion:*' matcher-list 'm:{[:lower:]}={[:upper:]}' '+m:{[:upper:]}={[:lower:]}'
    
  4. 大文字小文字に関わらず, 候補が見つからない時のみ文字種を無視した補完をする.

    zstyle ':completion:*' matcher-list '' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]}'
    
  5. 通常補完 -> (小文字 -> 大文字) -> (小文字 -> 大文字 + 大文字 -> 小文字).

    zstyle ':completion:*' matcher-list '' 'm:{[:lower:]}={[:upper:]}' '+m:{[:upper:]}={[:lower:]}'
    

複雑なパターンにも対応してくれますね!

参考: 第5回 zshの誇る花形機能“補完”:zshで究極のオペレーションを|gihyo.jp … 技術評論社

22
15
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
22
15