Completion is the single biggest productivity win of zsh, and it needs two lines to enable.
Zsh's completion system (compsys) knows the options and arguments of hundreds of commands. It is enabled by loading and running compinit, which frameworks such as Oh My Zsh do for you. Once on:
git checkout <Tab>offers branches,ssh <Tab>hosts from~/.ssh/config,kill <Tab>processes,tar -<Tab>options with descriptions,- partial paths expand:
cd /u/lo/b<Tab>becomescd /usr/local/bin/, - pressing Tab again cycles through candidates, and Ctrl-D lists them without inserting.
Behaviour is configured with zstyle, which sets a style for a context pattern. The two most popular: zstyle ':completion:*' menu select gives an arrow-key menu, and a matcher-list that makes matching case-insensitive. Styles are covered in depth when you write your own completions.
compinit caches what it finds in ~/.zcompdump. If a newly installed tool has no completion, delete that file and start a new shell. compinit also checks that completion directories are not writable by other users and warns about "insecure directories"; compaudit lists them so you can fix their permissions instead of silencing the check.
Keep compinit after any changes to fpath (plugins add directories there), otherwise their completions are not found.
Example
# ~/.zshrc
autoload -Uz compinit && compinit # turn on the completion system
zstyle ':completion:*' menu select # arrow-key menu for candidates
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}' # case-insensitive
zstyle ':completion:*:descriptions' format '%B%d%b' # bold group headings
# Then try, pressing Tab where marked:
# cd /u/lo/b<Tab> -> cd /usr/local/bin/
# git checkout ma<Tab> -> matching branch names
# tar -<Tab> -> every option with a description
# kill <Tab> -> running processes with their PIDs
# ssh <Tab> -> hosts from ~/.ssh/config and known_hosts
compaudit # lists insecure completion dirs, if any
rm -f ~/.zcompdump && exec zsh # rebuild the completion cacheRemember
- autoload -Uz compinit && compinit enables completion
- zstyle ':completion:*' menu select gives an interactive menu
- Delete ~/.zcompdump when new completions do not show up
Watch out for
- Calling compinit before plugins add their directories to fpath, so their completions are missing.