2 " Language: Zsh shell script
3 " Maintainer: Nikolai Weibull <source@pcppopper.org>
4 " URL: http://www.pcppopper.org/vim/syntax/pcp/zsh/
5 " Latest Revision: 2004-12-12
6 " arch-tag: 2e2c7097-99cb-4b87-a771-3a819b69995e
10 elseif exists("b:current_syntax")
14 " Set iskeyword since we need `-' (and potentially others) in keywords.
15 " For version 5.x: Set it globally
16 " For version 6.x: Set it locally
18 command -nargs=1 SetIsk setlocal iskeyword=<args>
20 command -nargs=1 SetIsk set iskeyword=<args>
26 syn keyword zshTodo contained TODO FIXME XXX NOTE
29 syn region zshComment matchgroup=zshComment start='\%(^\|\s\)#' end='$' contains=zshTodo
32 syn match zshPreProc '^\%1l#\%(!\|compdef\|autoload\).*$'
35 syn match zshQuoted '\\.'
36 syn region zshString matchgroup=zshStringDelimiter start=+"+ end=+"+ contains=zshQuoted,@zshDerefs,@zshSubst
37 syn region zshString matchgroup=zshStringDelimiter start=+'+ end=+'+
38 " XXX: This should probably be more precise, but Zsh seems a bit confused about it itself
39 syn region zshPOSIXString matchgroup=zshStringDelimiter start=+\$'+ end=+'+ contains=zshQuoted
40 syn match zshJobSpec '%\(\d\+\|?\=\w\+\|[%+-]\)'
42 " Precommand Modifiers
43 syn keyword zshPrecommand noglob nocorrect exec command builtin - time
46 syn keyword zshDelimiter do done
49 syn keyword zshConditional if then elif else fi case in esac select
52 syn keyword zshRepeat for while until repeat foreach
55 syn keyword zshException always
58 syn keyword zshKeyword function nextgroup=zshKSHFunction skipwhite
61 syn match zshKSHFunction contained '\k\+'
62 syn match zshFunction '^\s*\k\+\ze\s*()'
65 syn match zshOperator '||\|&&\|;\|&!\='
69 " Do nothing for now TODO: do something
71 syn region zshHereDoc matchgroup=zshRedir start='<<\s*\z(\S*\)' end='^\z1$' contains=@zshSubst
72 syn region zshHereDoc matchgroup=zshRedir start='<<-\s*\z(\S*\)' end='^\s*\z1$' contains=@zshSubst
73 syn region zshHereDoc matchgroup=zshRedir start='<<\s*\(["']\)\z(\S*\)\1' end='^\z1$'
74 syn region zshHereDoc matchgroup=zshRedir start='<<-\s*\(["']\)\z(\S*\)\1' end='^\s*\z1$'
78 syn match zshRedir '\d\=\(<\|<>\|<<<\|<&\s*[0-9p-]\=\)'
79 syn match zshRedir '\d\=\(>\|>>\|>&\s*[0-9p-]\=\|&>\|>>&\|&>>\)[|!]\='
80 syn match zshRedir '|&\='
82 " Variable Assignments
83 syn match zshVariable '\<\h\w*\ze+\=='
84 " XXX: how safe is this?
85 syn region zshVariable oneline matchgroup=zshVariable start='\$\@<!\<\h\w*\[' end='\]\ze+\==' contains=@zshSubst
87 " Variable Dereferencing
88 syn cluster zshDerefs contains=zshShortDeref,zshLongDeref,zshDeref
90 if !exists("g:zsh_syntax_variables")
91 let s:zsh_syntax_variables = 'all'
93 let s:zsh_syntax_variables = g:zsh_syntax_variables
96 syn match zshShortDeref '\$[!#$*@?_-]\w\@!'
97 syn match zshShortDeref '\$[=^~]*[#+]*\d\+\>'
99 syn match zshLongDeref '\$\%(ARGC\|argv\|status\|pipestatus\|CPUTYPE\|EGID\|EUID\|ERRNO\|GID\|HOST\|LINENO\|LOGNAME\)'
100 syn match zshLongDeref '\$\%(MACHTYPE\|OLDPWD OPTARG\|OPTIND\|OSTYPE\|PPID\|PWD\|RANDOM\|SECONDS\|SHLVL\|signals\)'
101 syn match zshLongDeref '\$\%(TRY_BLOCK_ERROR\|TTY\|TTYIDLE\|UID\|USERNAME\|VENDOR\|ZSH_NAME\|ZSH_VERSION\|REPLY\|reply\|TERM\)'
103 syn match zshDeref '\$[=^~]*[#+]*\h\w*\>'
106 syn match zshCommands '\%(^\|\s\)[.:]\ze\s'
107 syn keyword zshCommands alias autoload bg bindkey break bye cap cd chdir
108 syn keyword zshCommands clone comparguments compcall compctl compdescribe
109 syn keyword zshCommands compfiles compgroups compquote comptags comptry
110 syn keyword zshCommands compvalues continue declare dirs disable disown
111 syn keyword zshCommands echo echotc echoti emulate enable eval exec exit
112 syn keyword zshCommands export false fc fg functions getcap getln
113 syn keyword zshCommands getopts hash history jobs kill let limit
114 syn keyword zshCommands log logout popd print printf pushd pushln
115 syn keyword zshCommands pwd r read readonly rehash return sched set
116 syn keyword zshCommands setcap setopt shift source stat suspend test times
117 syn keyword zshCommands trap true ttyctl type ulimit umask unalias
118 syn keyword zshCommands unfunction unhash unlimit unset unsetopt vared
119 syn keyword zshCommands wait whence where which zcompile zformat zftp zle
120 syn keyword zshCommands zmodload zparseopts zprof zpty zregexparse zsocket
121 syn keyword zshCommands zstyle ztcp
124 syn keyword zshTypes float integer local typeset
127 " XXX: this may be too much
128 syn match zshSwitches '\s\zs--\=[a-zA-Z0-9-]\+'
131 syn match zshNumber '[-+]\=0x\x\+\>'
132 syn match zshNumber '[-+]\=0\o\+\>'
133 syn match zshNumber '[-+]\=\d\+#[-+]\=\w\+\>'
134 syn match zshNumber '[-+]\=\d\+\.\d\+\>'
137 syn cluster zshSubst contains=zshSubst,zshOldSubst
138 syn region zshSubst matchgroup=zshSubstDelim transparent start='\$(' skip='\\)' end=')' contains=TOP
139 syn region zshSubst matchgroup=zshSubstDelim transparent start='\$((' skip='\\)' end='))' contains=TOP
140 syn region zshSubst matchgroup=zshSubstDelim start='\${' skip='\\}' end='}' contains=@zshSubst
141 syn region zshOldSubst matchgroup=zshSubstDelim start=+`+ skip=+\\`+ end=+`+ contains=TOP,zshOldSubst
143 " Define the default highlighting.
144 " For version 5.7 and earlier: only when not done already
145 " For version 5.8 and later: only when an item doesn't have highlighting yet
146 if version >= 508 || !exists("did_zsh_syn_inits")
148 let did_zsh_syn_inits = 1
149 command -nargs=+ HiLink hi link <args>
151 command -nargs=+ HiLink hi def link <args>
155 HiLink zshComment Comment
156 HiLink zshPreProc PreProc
157 HiLink zshQuoted SpecialChar
158 HiLink zshString String
159 HiLink zshStringDelimiter zshString
160 HiLink zshPOSIXString zshString
161 HiLink zshJobSpec Special
162 HiLink zshPrecommand Special
163 HiLink zshDelimiter Keyword
164 HiLink zshConditional Conditional
165 HiLink zshException Exception
166 HiLink zshRepeat Repeat
167 HiLink zshKeyword Keyword
168 HiLink zshFunction Function
169 HiLink zshKSHFunction zshFunction
170 HiLink zshHereDoc String
171 HiLink zshOperator Operator
172 HiLink zshRedir Operator
173 HiLink zshVariable Identifier
174 HiLink zshDereferencing PreProc
175 if s:zsh_syntax_variables =~ 'short\|all'
176 HiLink zshShortDeref zshDereferencing
178 HiLink zshShortDeref None
180 if s:zsh_syntax_variables =~ 'long\|all'
181 HiLink zshLongDeref zshDereferencing
183 HiLink zshLongDeref None
185 if s:zsh_syntax_variables =~ 'all'
186 HiLink zshDeref zshDereferencing
188 HiLink zshDerefDeref None
190 HiLink zshCommands Keyword
192 HiLink zshSwitches Special
193 HiLink zshNumber Number
194 HiLink zshSubst PreProc
195 HiLink zshOldSubst zshSubst
196 HiLink zshSubstDelim zshSubst
201 let b:current_syntax = "zsh"
203 " vim: set sts=2 sw=2: