bf838200263a4af319ba3b511d6bca9f57dd128e
[zsh.git] / .zsh / zsh-syntax-highlighting / highlighters / main / README.md
1 zsh-syntax-highlighting / highlighters / main
2 ---------------------------------------------
3
4 This is the `main` highlighter, that highlights:
5
6 * Commands
7 * Options
8 * Arguments
9 * Paths
10 * Strings
11
12 This highlighter is active by default.
13
14
15 ### How to tweak it
16
17 This highlighter defines the following styles:
18
19 * `unknown-token` - unknown tokens / errors
20 * `reserved-word` - shell reserved words (`if`, `for`)
21 * `alias` - aliases
22 * `suffix-alias` - suffix aliases (requires zsh 5.1.1 or newer)
23 * `builtin` - shell builtin commands (`shift`, `pwd`, `zstyle`)
24 * `function` - function names
25 * `command` - command names
26 * `precommand` - precommand modifiers (e.g., `noglob`, `builtin`)
27 * `commandseparator` - command separation tokens (`;`, `&&`)
28 * `hashed-command` - hashed commands
29 * `path` - existing filenames
30 * `path_pathseparator` - path separators in filenames (`/`); if unset, `path` is used (default)
31 * `path_prefix` - prefixes of existing filenames
32 * `path_prefix_pathseparator` - path separators in prefixes of existing filenames (`/`); if unset, `path_prefix` is used (default)
33 * `globbing` - globbing expressions (`*.txt`)
34 * `history-expansion` - history expansion expressions (`!foo` and `^foo^bar`)
35 * `single-hyphen-option` - single hyphen options (`-o`)
36 * `double-hyphen-option` - double hyphen options (`--option`)
37 * `back-quoted-argument` - backquoted expressions (`` `foo` ``)
38 * `single-quoted-argument` - single quoted arguments (`` 'foo' ``)
39 * `double-quoted-argument` - double quoted arguments (`` "foo" ``)
40 * `dollar-quoted-argument` - dollar quoted arguments (`` $'foo' ``)
41 * `dollar-double-quoted-argument` - parameter expansion inside double quotes (`$foo` inside `""`)
42 * `back-double-quoted-argument` - back double quoted arguments (`\x` inside `""`)
43 * `back-dollar-quoted-argument` - back dollar quoted arguments (`\x` inside `$''`)
44 * `assign` - parameter assignments
45 * `redirection` - redirection operators (`<`, `>`, etc)
46 * `comment` - comments, when `setopt INTERACTIVE_COMMENTS` is in effect (`echo # foo`)
47 * `arg0` - a command word other than one of those enumrated above (other than a command, precommand, alias, function, or shell builtin command).
48 * `default` - everything else
49
50 To override one of those styles, change its entry in `ZSH_HIGHLIGHT_STYLES`,
51 for example in `~/.zshrc`:
52
53 # Declare the variable
54 typeset -A ZSH_HIGHLIGHT_STYLES
55
56 # To differentiate aliases from other command types
57 ZSH_HIGHLIGHT_STYLES[alias]='fg=magenta,bold'
58
59 # To have paths colored instead of underlined
60 ZSH_HIGHLIGHT_STYLES[path]='fg=cyan'
61
62 # To disable highlighting of globbing expressions
63 ZSH_HIGHLIGHT_STYLES[globbing]='none'
64
65 The syntax for values is the same as the syntax of "types of highlighting" of
66 the zsh builtin `$zle_highlight` array, which is documented in [the `zshzle(1)`
67 manual page][zshzle-Character-Highlighting].
68
69 ### Useless trivia
70
71 #### Forward compatibility.
72
73 zsh-syntax-highlighting attempts to be forward-compatible with zsh.
74 Specifically, we attempt to facilitate highlighting _command word_ types that
75 had not yet been invented when this version of zsh-syntax-highlighting was
76 released.
77
78 A _command word_ is something like a function name, external command name, et
79 cetera. (See
80 [Simple Commands & Pipelines in `zshmisc(1)`][zshmisc-Simple-Commands-And-Pipelines]
81 for a formal definition.)
82
83 If a new _kind_ of command word is ever added to zsh — something conceptually
84 different than "function" and "alias" and "external command" — then command words
85 of that (new) kind will be highlighted by the style `arg0_$kind`,
86 where `$kind` is the output of `type -w` on the new kind of command word. If that
87 style is not defined, then the style `arg0` will be used instead.
88
89 [zshmisc-Simple-Commands-And-Pipelines]: http://zsh.sourceforge.net/Doc/Release/Shell-Grammar.html#Simple-Commands-_0026-Pipelines
90
91 [zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting