dotfiles

zsh-syntax-highlighting / highlighters
Login

zsh-syntax-highlighting / highlighters

Syntax highlighting is done by pluggable highlighters:

Highlighter-independent settings

By default, all command lines are highlighted. However, it is possible to prevent command lines longer than a fixed number of characters from being highlighted by setting the variable ${ZSH_HIGHLIGHT_MAXLENGTH} to the maximum length (in characters) of command lines to be highlighter. This is useful when editing very long command lines (for example, with the fned utility function). Example:

ZSH_HIGHLIGHT_MAXLENGTH=512

How to activate highlighters

To activate an highlighter, add it to the ZSH_HIGHLIGHT_HIGHLIGHTERS array in ~/.zshrc, for example:

ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets pattern cursor)

By default, $ZSH_HIGHLIGHT_HIGHLIGHTERS is unset and only the main highlighter is active.

How to tweak highlighters

Highlighters look up styles from the ZSH_HIGHLIGHT_STYLES associative array. Navigate into the individual highlighters' documentation to see what styles (keys) each highlighter defines; the syntax for values is the same as the syntax of "types of highlighting" of the zsh builtin $zle_highlight array, which is documented in the zshzle(1) manual page.

Some highlighters support additional configuration parameters; see each highlighter's documentation for details and examples.

How to implement a new highlighter

To create your own acme highlighter:

If you need to test which options the user has set, test zsyh_user_options with a sensible default if the option is not present in supported zsh versions. For example:

```zsh
[[ ${zsyh_user_options[ignoreclosebraces]:-off} == on ]]
```

The option name must be all lowercase with no underscores and not an alias.