Enter the following two commands:
autoload -U compinit compinit
Some functions, like _apt and _dpkg, are very slow. You can use a cache in order to proxy the list of results (like the list of available debian packages).
zstyle ':completion:*' use-cache on zstyle ':completion:*' cache-path ~/.zsh/cache
With helper functions, you can avoid having to complete at all in many cases, but if you do, you might want to fall into menu selection immediately and to have the words sorted by time:
xdvi() { command xdvi ${*:-*.dvi(om[1])} }
zstyle ':completion:*:*:xdvi:*' menu yes select
zstyle ':completion:*:*:xdvi:*' file-sort time
when completing inside array or association subscripts, the array elements are more useful than parameters so complete them first:
zstyle ':completion:*:*:-subscript-:*' tag-order indexes parameters
in recent zsh 4.1.x only: complete the names of parameters we have special completions for in parameter assignments:
zstyle ':completion::*:(-command-|export):*' fake-parameters ${${${_comps[(I)-value-*]#*,}%%,*}:#-*-}
If you end up using a directory as argument, this will remove the trailing slash (useful in ln):
zstyle ':completion:*' squeeze-slashes true
How to complete in the middle of some text ignoring the suffix. (people coming from tcsh might miss this big time).
Just bind TAB to expand-or-complete-prefix:
bindkey '^i' expand-or-complete-prefix
Then /usr/loc<TAB>ljkabcb completes just like if you had /usr/loc<TAB>.
Quoting Bart Schaefer from zsh-users #8059:
If you're using compsys, the right way to do this is by adding to your completer zstyle:
_force_rehash() {
(( CURRENT == 1 )) && rehash
return 1 # Because we didn't really complete anything
}
zstyle ':completion:*' completer \
_oldlist _expand _force_rehash _complete ...
(where ”…” is the rest of whatever you already have in that style).