zsh-syntax-highlighting works by hooking intothe Zsh Line Editor (ZLE) and computing syntax highlighting forthe command-line buffer asit stands atthetime z-sy-h's hook is invoked.
In zsh 5.2and older, hooks into ZLE by wrapping ZLE widgets. It must be sourced after all custom widgets have been created (i.e., after all calls andafterrunning ) in order to be able to wrap all of them. Widgets created after z-sy-h is sourced will work, but will not update the syntax highlighting.zsh-syntax-highlighting.zshzle -Ncompinit
In zsh newer than 5.8 (not including 5.8 itself), zsh-syntax-highlighting uses the facility to install a hook. Hooks are runin order of registration, therefore, z-sy-h must be sourced (and register its hook) after anything elsethat adds hooks that modify the command-line buffer.add-zle-hook-widgetzle-line-pre-redraw