4

Currently I have this in my ~/.zshrc:

zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'

AFAIU 'm:{a-z}={A-Za-z}' means that I will get case-insensitive tab completion, e.g. foo will tab-complete to Foobar (if that exists). And 'r:|[._-]=* r:|=*' 'l:|=* r:|=*' means that I will get matches for later parts of a word, e.g. bar will tab-complete to foobar (if that exists). But those partial matches are not case-insensitive. So for example bar will not tab-complete to FooBar (again, in case that exists).

Is there a way to get that working?

1 Answer 1

9

The matchers in your matcher-list are always tried one at a time, until one of them returns at least one match. By default, each matcher completely replaces the previous one. To instead make the next matcher include the previous one, you need to prefix it with +:

zstyle ':completion:*' matcher-list \
    'm:{[:lower:]}={[:upper:]}' \
    '+r:|[._-]=* r:|=*' \
    '+l:|=*'

See the matcher-list completion style doc.


And 'r:|[._-]=* r:|=*' 'l:|=* r:|=*' means that I will get matches for later parts of a word, e.g. bar will tab-complete to foobar (if that exists).

Not exactly:

  • If <word> is the string on the command line that’s being completed, then, by default, Zsh will return completions matching the glob pattern <word>* — except when COMPLETE_IN_WORD is set, which case it will create a completion pattern by inserting the * at the cursor position instead.
  • r:|[._-]=* means “For each occurrence in <word> of the empty string followed to the right (r) by ., _ or -, insert * between them (|) in the completion pattern.”
  • r:|=* means “If <word> ends on the right with an empty string (which is always true), suffix the completion pattern with *.”
  • l:|=* means “If <word> starts on the left with an empty string (always true), prefix the completion pattern with *.”
  • Multiple subpatterns inserted at the same index in the parent completion pattern are combined with a logical OR.

See the completion matching control docs for a more in-depth explanation.

3
  • Awesome, thanks a lot! 'm:[:lower:]=[:upper:]' didn't work for me, but adding + to my existing matchers worked. :)
    – shahn
    Commented Aug 16, 2021 at 1:42
  • Ah, sorry, that was a typo. It’s fixed now. Commented Aug 16, 2021 at 5:28
  • Oh my god, just the line of code I was looking for! Brilliant
    – Graunephar
    Commented Jan 3, 2023 at 13:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.