This works

Normally, zsh's tab completion works well.

$ touch foo-1-bar foo-2-bar
$ touch f<Tab>
$ touch foo--bar
            ^ cursor here

Pressing Tab again brings up a menu from which I can select files.

$ touch foo--bar
foo-1-bar  foo-2-bar

This doesn't

However, this doesn't seem to work with strings where the beginning and end match. For example:

touch foo-bar foo-foo-bar
touch f<Tab>
touch foo-bar
         ^ cursor here. <tab> again.
touch foo-bar
              ^ cursor here.

No menu is brought up, and there is no opportunity to select foo-foo-bar. Is this expected behaviour or a bug? Is there a setting to make a menu appear in the latter scenario?

I'm using oh-my-zsh. I attempted removing all the completion-related lines from ~/.zshrc, but this made no difference.

  • 3
    Remove oh-my-zsh, in .zshrc put autoload -U compinit && compinit; zstyle ':completion:*' menu select. – jimmij Feb 2 '16 at 10:55
  • Hm, that seems to work. I only need to remove the line sourcing oh-my-zsh, the second line is not necessary. Is there a way to make completion work without removing oh-my-zsh? – Sparhawk Feb 2 '16 at 11:43
  • 1
    Why do you need this oh-crap? – jimmij Feb 2 '16 at 12:12
  • I… don't know. I just started using zsh, and many tutorials suggest oh-my-zsh. FWIW I like the prompt that I've picked. I presume that may be workable without oh-my-zsh though. – Sparhawk Feb 2 '16 at 12:21

As per the comments, I tried disabling oh-my-zsh, which fixed this problem. I then went through the oh-my-zsh source, selectively disabling modules.

I previously had CASE_SENSITIVE="true", but commenting out this line fixed it for me. Apparently it's a known bug.

To fix it, I could put the following line in ~/.zshrc after sourcing oh-my-zsh.

zstyle ':completion:*' matcher-list 'r:|=*' 'l:|=* r:|=*'
  • Oh-My-Zsh is a bloated ratmangle; removing it entirely would be the only sensible approach. – jasonwryan Feb 3 '16 at 6:26
  • @jasonwryan That seems to be the general opinion here! In particular, this bug had a simple proposed fix from three years ago, but was then closed for some unknown reason by the developer. And the number of open issues (many unreplied) is impressive. I'll take yours and jimmij's advice and look to customise zsh myself. (FWIW the "bloatedness" doesn't seem to affect my performance, but I'm more worried about bugs introduced by oh-my-zsh. – Sparhawk Feb 3 '16 at 8:05
  • @Sparhawk, this not always works for me. Can you help please? I have details here. – ericbn May 11 '18 at 15:41

Personally, I prefer this solution much more - http://zsh.sourceforge.net/FAQ/zshfaq04.html#l50, It works like completion in tcsh, and completes words, that are before cursor only.

Just use

    bindkey '\CI' expand-or-complete-prefix

instead of

    bindkey '\CI' expand-or-complete

(Which is by default).

  • I'm now using zim, so I can't really confirm this. However, thanks for posting, and welcome to U/L! (Have an upvote to help get you past the initial limitations.) – Sparhawk Sep 7 '17 at 11:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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