I got my zsh autocompletion working the way I wanted a while ago, with one exception I just noticed.

If there is two empty directories looking like this: a/b/ and a1/b/c and I cd a/b/ and tab to see more, there is nothing more, so autocomplete automatically switches to a1/b/c, which almost caused me to overwrite files in the wrong directory.

My current autocomplete section in .zshrc looks like this:

autoload -Uz compinit
zstyle ':completion:*' menu select
zmodload zsh/complist

What do I have to change to just forbid autocomplete to change directories I already typed / selected but keep the rest of my current autocomplete config in tact?

A nudge in the direction of the part of the documentation where I could have found this myself would be much appreciated, I don't seem to be able to find it for the life of me.

Thank you.

1 Answer 1


Turn on the accept-exact-dirs completion style.

zstyle :completion::complete:cd::paths accept-exact-dirs true

How to find this empirically: turn on traces (set -x), then enter cd a/b/ and press Tab. In the trace, find where a1 is first mentioned, then look before. This sort of sensible configuration option usually exists as a style which can be configured with zstyle.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .