Completions Management
Summary
Section titled “Summary”Zinit intercepts compdef calls made before compinit runs, stores them, and replays them afterwards — allowing a single compinit call regardless of plugin load order, which dramatically reduces startup time.
Details
Section titled “Details”Normally, Zsh’s compdef function is only available after compinit has been called. Plugins that call compdef before compinit would error. Zinit solves this by providing a stub compdef that records every call in an array. After compinit is called, zinit cdreplay replays all recorded calls against the real compdef.
Zinit also does not use $FPATH for completion discovery the way traditional plugin managers do. It installs completion files into $ZINIT[COMPLETIONS_DIR] and manages them independently, so loading many plugins does not pollute $FPATH with many entries.
Key commands:
zinit cdreplay [-q]— replay savedcompdefcalls. Run aftercompinit.zinit cdclear [-q]— discard all savedcompdefcalls (useful to ignore completions from a specific plugin).zinit creinstall {plg-spec}— install completions for a plugin.zinit cuninstall {plg-spec}— uninstall completions.zinit completions— list installed completions.zinit cdisable/zinit cenable— toggle individual completion.zinit cclear— remove stray or broken completions.
Without Turbo mode: call autoload -Uz compinit; compinit after all plugins load, then call zinit cdreplay -q.
With Turbo mode: do not call compinit in the main body of .zshrc. Instead, add atinit'zicompinit; zicdreplay' (or atload'zicompinit') to the last syntax-highlighting or completion plugin loaded with wait. The helper zicompinit runs autoload -Uz compinit; compinit.
Blocking unwanted completions: use blockf ice to prevent a plugin from adding entries to $FPATH, letting Zinit manage its completions instead. Use nocompletions ice to skip completion installation entirely for a plugin.
System-wide compinit: on Ubuntu and NixOS, a system-wide compinit may fire from /etc/zshrc before your config runs. Suppress it (skip_global_compinit=1 in ~/.zshenv on Ubuntu, programs.zsh.enableGlobalCompInit = false on NixOS) to avoid double-initialization and slow startup.
Examples
Section titled “Examples”# Without Turbo — call compinit once after all pluginssource "${ZINIT_HOME}/zinit.zsh"zinit load "some/plugin"zinit load "other/plugin"autoload -Uz compinitcompinitzinit cdreplay -q
# With Turbo — defer compinit into the last plugin's hookzi for \ atload"zicompinit; zicdreplay" \ blockf \ lucid \ wait \ zsh-users/zsh-completions
# Ignore completions from a specific pluginzi snippet OMZP::gitzi cdclear -q # discard git plugin's compdefs
# Mark completion directly (single _file snippet)zi ice as"completion"zi snippet OMZP::docker/_docker
# Block a plugin from polluting fpathzi ice blockfzi light zsh-users/zsh-completions
# Ubuntu: suppress global compinit (add to ~/.zshenv)skip_global_compinit=1Caveats / Common Mistakes
Section titled “Caveats / Common Mistakes”zicdreplaymust be called afterzicompinit— reversing the order meanscompdefis not yet available when replay happens.- Double
compinitcalls (e.g. from system/etc/zshrcplus your.zshrc) can slow startup from ~0.16 s to ~0.98 s. Disable the system call where possible. cdcleardiscards all compdefs accumulated up to that point; place it immediately after the plugin whose completions you want to ignore.