nakanomikuorg / arch-guide

✨ archlinux 简明指南 | 本指南包含从 archlinux 安装、显卡驱动、日常软件配置、多媒体制作、编程等你可能需要的全部内容 | 提供在线文档 ✨
https://arch.icekylin.online/
Creative Commons Attribution Share Alike 4.0 International
1.43k stars 138 forks source link

fix zsh highlight setting #220

Closed xiwuaya closed 2 months ago

xiwuaya commented 2 months ago

根据zsh-syntax-highlighting 的github主页

Why must zsh-syntax-highlighting.zsh be sourced at the end of the .zshrc file?

zsh-syntax-highlighting works by hooking into the Zsh Line Editor (ZLE) and computing syntax highlighting for the command-line buffer as it stands at the time z-sy-h's hook is invoked.

In zsh 5.2 and older, zsh-syntax-highlighting.zsh hooks into ZLE by wrapping ZLE widgets. It must be sourced after all custom widgets have been created (i.e., after all zle -N calls and after running compinit) 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.

In zsh newer than 5.8 (not including 5.8 itself), zsh-syntax-highlighting uses the add-zle-hook-widget facility to install a zle-line-pre-redraw hook. Hooks are run in order of registration, therefore, z-sy-h must be sourced (and register its hook) after anything else that adds hooks that modify the command-line buffer.

在高于5.8版本的zsh中,zsh-syntax-highlighting.zsh需要在文件的末尾被引用才能正确的注册hook并生效