Update zsh-syntax-highlighting plugin
[zsh.git] / .zsh / zsh-syntax-highlighting / docs / highlighters / main.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 * `command-substitution` - command substitutions (`$(echo foo)`)
36 * `command-substitution-unquoted` - an unquoted command substitution (`$(echo foo)`)
37 * `command-substitution-quoted` - a quoted command substitution (`"$(echo foo)"`)
38 * `command-substitution-delimiter` - command substitution delimiters (`$(` and `)`)
39 * `command-substitution-delimiter-unquoted` - an unquoted command substitution delimiters (`$(` and `)`)
40 * `command-substitution-delimiter-quoted` - a quoted command substitution delimiters (`"$(` and `)"`)
41 * `process-substitution` - process substitutions (`<(echo foo)`)
42 * `process-substitution-delimiter` - process substitution delimiters (`<(` and `)`)
43 * `single-hyphen-option` - single-hyphen options (`-o`)
44 * `double-hyphen-option` - double-hyphen options (`--option`)
45 * `back-quoted-argument` - backtick command substitution (`` `foo` ``)
46 * `back-quoted-argument-unclosed` - unclosed backtick command substitution (`` `foo ``)
47 * `back-quoted-argument-delimiter` - backtick command substitution delimiters (`` ` ``)
48 * `single-quoted-argument` - single-quoted arguments (`` 'foo' ``)
49 * `single-quoted-argument-unclosed` - unclosed single-quoted arguments (`` 'foo ``)
50 * `double-quoted-argument` - double-quoted arguments (`` "foo" ``)
51 * `double-quoted-argument-unclosed` - unclosed double-quoted arguments (`` "foo ``)
52 * `dollar-quoted-argument` - dollar-quoted arguments (`` $'foo' ``)
53 * `dollar-quoted-argument-unclosed` - unclosed dollar-quoted arguments (`` $'foo ``)
54 * `rc-quote` - two single quotes inside single quotes when the `RC_QUOTES` option is set (`` 'foo''bar' ``)
55 * `dollar-double-quoted-argument` - parameter expansion inside double quotes (`$foo` inside `""`)
56 * `back-double-quoted-argument` - backslash escape sequences inside double-quoted arguments (`\"` in `"foo\"bar"`)
57 * `back-dollar-quoted-argument` - backslash escape sequences inside dollar-quoted arguments (`\x` in `$'\x48'`)
58 * `assign` - parameter assignments (`x=foo` and `x=( )`)
59 * `redirection` - redirection operators (`<`, `>`, etc)
60 * `comment` - comments, when `setopt INTERACTIVE_COMMENTS` is in effect (`echo # foo`)
61 * `named-fd` - named file descriptor (`echo foo {fd}>&2`)
62 * `arg0` - a command word other than one of those enumerated above (other than a command, precommand, alias, function, or shell builtin command).
63 * `default` - everything else
64
65 To override one of those styles, change its entry in `ZSH_HIGHLIGHT_STYLES`,
66 for example in `~/.zshrc`:
67
68 # Declare the variable
69 typeset -A ZSH_HIGHLIGHT_STYLES
70
71 # To differentiate aliases from other command types
72 ZSH_HIGHLIGHT_STYLES[alias]='fg=magenta,bold'
73
74 # To have paths colored instead of underlined
75 ZSH_HIGHLIGHT_STYLES[path]='fg=cyan'
76
77 # To disable highlighting of globbing expressions
78 ZSH_HIGHLIGHT_STYLES[globbing]='none'
79
80 The syntax for values is the same as the syntax of "types of highlighting" of
81 the zsh builtin `$zle_highlight` array, which is documented in [the `zshzle(1)`
82 manual page][zshzle-Character-Highlighting].
83
84 #### Parameters
85
86 To avoid partial path lookups on a path, add the path to the `X_ZSH_HIGHLIGHT_DIRS_BLACKLIST` array.
87 This interface is still experimental.
88
89 X_ZSH_HIGHLIGHT_DIRS_BLACKLIST+=(/mnt/slow_share)
90
91 ### Useless trivia
92
93 #### Forward compatibility.
94
95 zsh-syntax-highlighting attempts to be forward-compatible with zsh.
96 Specifically, we attempt to facilitate highlighting _command word_ types that
97 had not yet been invented when this version of zsh-syntax-highlighting was
98 released.
99
100 A _command word_ is something like a function name, external command name, et
101 cetera. (See
102 [Simple Commands & Pipelines in `zshmisc(1)`][zshmisc-Simple-Commands-And-Pipelines]
103 for a formal definition.)
104
105 If a new _kind_ of command word is ever added to zsh — something conceptually
106 different than "function" and "alias" and "external command" — then command words
107 of that (new) kind will be highlighted by the style `arg0_$kind`,
108 where `$kind` is the output of `type -w` on the new kind of command word. If that
109 style is not defined, then the style `arg0` will be used instead.
110
111 [zshmisc-Simple-Commands-And-Pipelines]: http://zsh.sourceforge.net/Doc/Release/Shell-Grammar.html#Simple-Commands-_0026-Pipelines
112
113 [zshzle-Character-Highlighting]: http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html#Character-Highlighting