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?

- 4,059
- 5
- 39
- 59
1 Answers
autoload
, from man zshbuiltins
:
The flags
-z
and-k
mark the function to be autoloaded in native or ksh emulation, as if the optionKSH_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.
-
7*"-Uz"? Yes, that is "the right thing"[tm] almost always, so I won't discuss it here* - meh, the one part i was looking for isn't actually explained in the article – ThiefMaster Feb 14 '15 at 17:29
-
I haven't found further sources for `-Uz`, but my own interpretation of the man page is that `-z` marks autoloading via `zsh` (ie, 'native'), which is ideal because you're running zsh. `-U` prevents alias expansion, which is (presumably) good when loading functions because you may have alises that override function names, and the order of loading (alias, function vs function, alias) might break things. – simont Nov 23 '20 at 01:11