Context for those who know about zsh completion but not all its features: One of the unique and really useful features of zsh is as follows:

[/usr/dir1/dir2/dir3/]$ cd dir1 dirnew

i.e. If a user can replace a particular directory in the hierarchy with another. Its a very handy feature. (assuming dirnew does have dir2/dir3). If dirnew didn't have dir2/dir3, this command would fail.

I wonder how I can complete cd though, for long directory names. When I do cd <TAB>, besides the directories in the current directory, what should also show up is directories in the current hierarchy. Once I choose or type in one of the directories from the hierarchy, if I press <TAB> again, I should get completion options from the directories in parent which have a similar hierarchy. In the above example, say /usr/ has dirnew and diranother beisdes dir1. dirnew has dir2/dir3 but diranother is empty. cd dir1 <TAB> should give me new as an option, but not diranother.


Either you have an old version of Zsh or your configuration is breaking it. Zsh's cd completion has that feature and it works. You can verify it by running zsh without using any of your configs:

zsh -f # all settings at their default values
autoload compinit && compinit
mkdir -p tmp/a/b
mkdir -p tmp/c/b
mkdir -p tmp/b
cd tmp/a/b
cd a [TAB]

I am running Zsh 5.1 and it completes correctly to c. If I create a second possible completion, e.g. mkdir -p d/b, it gives me c and d.

  • Thanks for taking the time to answer although I'm on zsh 5.0 and don't see this, so would try out otherwise and then answer. – 0fnt Sep 14 '15 at 13:01
  • I don't think this is new. Did you try the script with your zsh? – Francisco Sep 15 '15 at 8:20
  • I did, yes. I follwed your exact steps and couldn't get it working. But thanks for the help. – 0fnt Sep 15 '15 at 11:26

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.