43

I switched to zsh completely on a previous arch install and I LOVED it mainly because arch is one of the distros that capitalizes your Documents, Downloads, Music and such directories in your ~ directory. Since I wasn't used to that and I use tab completion for almost everything in the terminal zsh was like heaven for me compared to bash.... I swear this feature used to be active automatically because I don't remember having to tweak anything to make it work that way. I probably figured it out on accident. xD But I would greatly like to have this feature restored on my new pc using zsh as my main shell, and if anyone knows how to do this I would really appreciate a reply. I tried activating every option in the completion configuration and that didn't seem to do the trick... so that brought me here.

PS: I used to be a lot more up to date with my Linux know-how, and my knowledge has grown stale... I'm trying to remedy that... (without the use of the shift key, as much as possible... haha)

cmaher
  • 103
  • 3
Aaron
  • 431
  • 1
  • 4
  • 3
  • 4
    Welcome to SU! To improve your style a comment: Your question is rather difficult to read, because there is a lot of unnecessary information. Please edit you question and try to concentrate on the relevant infos. Keep it short and simple `;)`. – mpy Jun 22 '16 at 16:59

1 Answers1

85

TL;DR: This is possible if you put these lines in your zsh config file, usually ~/.zshrc:

autoload -Uz compinit && compinit
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}'

A little bit more information:

This is possible when using the zsh completion system (started by autoload -Uz compinit && compinit) and is controlled by a zstyle:

zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}'

This tells zsh that small letters will match small and capital letters. (i.e. capital letters match only capital letters.)

If you want that capital letters also match small letters use instead:

zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}'

If you want case-insensitive matching only if there are no case-sensitive matches add '', e.g.

zstyle ':completion:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}'

See also the description of matcher-list in man zshcompsys.

mpy
  • 27,002
  • 7
  • 85
  • 97
  • 1
    @Aaron: Glad to hear. Please consider to accept my answer then as explained in the [SU tour](http://superuser.com/tour). – mpy Jun 23 '16 at 16:19
  • 4
    So where do I put `zstyle`? – inherithandle Nov 22 '18 at 14:44
  • @inherithandle: It's a normal shell (builtin) command, you can execute it on the command line. If you wan't that behavior permanent, put it into your `~/.zshrc`. – mpy Nov 22 '18 at 17:23
  • 2
    I have added the above setting to my `.zshrc` and sourced it, but it does not seem to work. I have also tried to use the command in command line to no avail. Any ideas on how to make it work? – jdhao Oct 09 '19 at 03:26
  • 1
    @jdhao: Maybe you haven't initialized the completion system, use some other 3rd party settings (d'oh-my-zsh), etc... so, this is too complex to debug in the comments. Try to construct a minimal(!) case of your config files and write a separate question; something like "Why have my zstyle settings no effect?" – mpy Oct 09 '19 at 17:19
  • 9
    @mpy Thanks for your kind reply. I have found that we need to add `autoload -Uz compinit && compinit` after the zstyle command to make the setting take effect. Maybe it is worthwhile to mention that in the answer for zsh novices like me... – jdhao Oct 09 '19 at 17:26
  • @jdhao: Yes, good point. I added this to the introductory sentence. – mpy Oct 09 '19 at 19:13
  • Please rewrite the answer so one doesn't have to scan all the comments to figure out what one needs to do. Like: (1) create a file (2) add "A" to the file (3) add "B" to the file This is superuser, not Serverfault or Stackoverflow ;) – jitbit Dec 26 '21 at 08:43
  • 2
    @jitbit: I added a "summary" with a snippet for easy copy&paste. I hope this will help to get this working faster. – mpy Dec 26 '21 at 11:15
  • 1
    @mpy thank you sir! – jitbit Dec 26 '21 at 12:18