zsh-syntax-highlighting README

The project's README from github.com/zsh-users/zsh-syntax-highlighting. As one markdown file: README.md.

zsh-syntax-highlighting Build Status

Fish shell-like syntax highlighting for Zsh.

Requirements: zsh 4.3.11+.

This package provides syntax highlighting for the shell zsh. It enables highlighting of commands whilst they are typed at a zsh prompt into an interactive terminal. This helps in reviewing commands before running them, particularly in catching syntax errors.

Some examples:

Before: Screenshot #1.1
After:  Screenshot #1.2

Before: Screenshot #2.1
After:  Screenshot #2.2

Before: Screenshot #3.1
After:  Screenshot #3.2

Before: Screenshot #4.1
After:  Screenshot #4.2

How to install

See INSTALL.md.

FAQ

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.

Highlighting the command line during an incremental history search (by default bound to to Ctrl+R in zsh's emacs keymap) requires zsh 5.4 or newer.

Under zsh versions older than 5.4, the zsh-default underlining of the matched portion of the buffer remains available, but zsh-syntax-highlighting's additional highlighting is unavailable. (Those versions of zsh do not provide enough information to allow computing the highlighting correctly.)

See issues #288 and #415 for details.

How are new releases announced?

There is currently no "push" announcements channel. However, the following alternatives exist:

How to tweak

Syntax highlighting is done by pluggable highlighter scripts. See the documentation on highlighters for details and configuration settings.

zsh-syntax-highlighting (zsh-users/zsh-syntax-highlighting)

Searching Database…

这是什么?这是一个 Zsh 插件,可以在你的交互式终端命令行中添加类似 Fish shell 的语法高亮,在你输入命令时实时为命令着色。
这是独立应用还是 Shell 插件?它是一个 Zsh 插件:通过 .zshrc 加载的脚本,会挂接到 Zsh Line Editor 上,实时为命令行着色。
我该如何安装并启用它?按照 INSTALL.md 中的步骤操作:先把脚本下载到本机,再在 .zshrc 中 source zsh-syntax-highlighting.zsh。
我需要哪个版本的 zsh?需要 Zsh 4.3.11 或更新版本;部分功能(如增量历史搜索时的高亮)需要 Zsh 5.4+。
为什么在 .zshrc 中加载它的位置很重要?必须放在 .zshrc 的最末尾,位于所有自定义 widget 和 compinit 之后。原因是它通过包装已有的 ZLE widget 来工作(在较新版本的 zsh 中则是注册钩子)。放在它之后添加的内容不会被包装,高亮也无法正确更新。
它在 Linux 和 macOS 上都能用吗?能。它是一个 Shell 层面的插件,只要能运行 Zsh 的地方都可以用,包括 Linux 和 macOS。
我能自定义哪些部分需要高亮吗?可以。高亮功能通过可插拔的高亮器(highlighter)脚本实现,README 中指向了单独的高亮器文档,其中介绍了相关配置选项。
新版本如何发布通知?没有主动推送的通知渠道,但你可以订阅 GitHub 的版本发布 RSS 源,或查看该项目在 anitya 上的条目。
增量历史搜索也会高亮吗?仅在 zsh 5.4 或更新版本上支持。在旧版本上,你只能看到 zsh 默认对匹配文本添加的下划线,看不到本插件额外的高亮。
Creator
zsh-users
Size
1.5 MB
Stars
23K
Updated
CommitOct 09
Age
15y
Commits · 90 Days