Search code examples
zshzshrczsh-completion

zsh completion difference


I have seen many do this
autoload -Uz compinit
compinit

and others do this
autoload -U compinit
compinit -i

I would like to know the difference. which one should I use?


Solution

  • autoload, from man zshbuiltins:

    The flags -z and -k mark the function to be autoloaded in native or ksh emulation, as if the option KSH_AUTOLOAD were unset or were set, respectively.

    The -U flag can be traced back: autoload is equivalent to function -u, which is equivalent to typeset -f. typeset, in a nutshell, is used to:

    Set or display attributes and values for shell parameters.

    When -f is used in combination with -U:

    [The -f flag causes] The names refer to functions rather than parameters. ... The -u and -U flags cause the function to be marked for autoloading; -U also causes alias expansion to be suppressed when the function is loaded.

    compinit is the completion initialization function used by compsys, the 'newer' Z-Shell completion system. See man zshcompsys for details.

    The -i flag is used to:

    to make compinit silently ignore all insecure files and directories use the option -i

    In general, you should be using autoload -Uz, according to this interesting read.