Take the 2-minute tour ×

How can I configure the Zsh tab-completion such that when I type cd ..<TAB> it expands to cd ../ and after pressing <TAB> again proposes the folders in the parent directory for completion?

E.g. it should show the same behavior as when typing for example cd Documents<TAB> which expands to cd Documents/ and after pressing <TAB> again proposes the folders in Documents for completion.

As a starting point for configuration I use an empty .zshrc and Zsh 4.3.9 from MacPorts.

share|improve this question

closed as off topic by Mikko Ohtamaa, Andrew, bmargulies, DCoder, Josh Caswell Sep 27 '12 at 19:49


for a long time I had this doubt –  JuanPablo Oct 18 '11 at 17:46

4 Answers 4

up vote 33 down vote accepted

Same problem with debian unstable, Ubuntu jaunty, both ship zsh 4.3.9. I know of multiple people with different configurations.

After reading http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=514152 I added

zstyle ':completion:*' special-dirs true

to my config and now everything works fine again.

share|improve this answer
man zshcompsys also suggests this: zstyle -e ':completion:*' special-dirs '[[ $PREFIX = (../)#(|.|..) ]] && reply=(..)' which avoids "./" and "../" being proposed all the time. –  exic Dec 9 '11 at 16:44

Put this into your ~/.zshrc:

autoload -Uz compinit

There is also a project with zsh functions/configurations for Mac OS X on http://code.google.com/p/zsh-templates-osx/ . Personally I think it's an overkill to use the whole package. But found it useful to cherry pick some tricks, functions, completions etc. and create my own .zshrc

share|improve this answer
Thank you, this configures exactly the behavior I was looking for. –  x-way Feb 19 '09 at 12:14
What does the option z does in your code? –  Masi Apr 30 '09 at 3:44
autload commandline options: -U -- suppress alias expansion for functions -k -- mark function for ksh-style autoloading -t -- turn on execution tracing for functions -w -- specify that arguments refer to files compiled with zcompile -z -- mark function for zsh-style autoloading –  f3lix May 3 '09 at 19:07

In fact I now discovered that the problem does not seem to come from the configuration. When using a .zshrc which only contains

autoload -Uz compinit

The tab-completion works as intended for cd ..<TAB> when using the default Mac OS X Zsh (4.3.4). But with the MacPorts Zsh (4.3.9) the tab-completion only works for other folders and not for ..

share|improve this answer

This may or may not be a useful answer - switch to bash, which does what you want out of the box.

share|improve this answer
That's somewhat like telling an vim user to switch to emacs, because he can't find a configuration switch... IMHO zsh is more powerful than bash and also comes with a great completion function. You just have to activate it... –  f3lix Feb 19 '09 at 11:01
