blob: ecd6f058b0e8efa9456c972cd6c33a2234a942af [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim syntax file
Bram Moolenaarc81e5e72007-05-05 18:24:42 +00002" Language: Zsh shell script
3" Maintainer: Nikolai Weibull <now@bitwi.se>
Bram Moolenaare37d50a2008-08-06 17:06:04 +00004" Latest Revision: 2008-07-17
Bram Moolenaar071d4272004-06-13 20:20:40 +00005
Bram Moolenaarc81e5e72007-05-05 18:24:42 +00006if exists("b:current_syntax")
Bram Moolenaar071d4272004-06-13 20:20:40 +00007 finish
8endif
9
Bram Moolenaarc81e5e72007-05-05 18:24:42 +000010let s:cpo_save = &cpo
11set cpo&vim
Bram Moolenaar071d4272004-06-13 20:20:40 +000012
Bram Moolenaar8c8de832008-06-24 22:58:06 +000013setlocal iskeyword+=-
Bram Moolenaar071d4272004-06-13 20:20:40 +000014
Bram Moolenaarc81e5e72007-05-05 18:24:42 +000015syn keyword zshTodo contained TODO FIXME XXX NOTE
Bram Moolenaar071d4272004-06-13 20:20:40 +000016
Bram Moolenaarc81e5e72007-05-05 18:24:42 +000017syn region zshComment display oneline start='\%(^\|\s\)#' end='$'
18 \ contains=zshTodo,@Spell
Bram Moolenaar071d4272004-06-13 20:20:40 +000019
Bram Moolenaarc81e5e72007-05-05 18:24:42 +000020syn match zshPreProc '^\%1l#\%(!\|compdef\|autoload\).*$'
Bram Moolenaar071d4272004-06-13 20:20:40 +000021
Bram Moolenaarc81e5e72007-05-05 18:24:42 +000022syn match zshQuoted '\\.'
23syn region zshString matchgroup=zshStringDelimiter start=+"+ end=+"+
24 \ contains=zshQuoted,@zshDerefs,@zshSubst
25syn region zshString matchgroup=zshStringDelimiter start=+'+ end=+'+
26" XXX: This should probably be more precise, but Zsh seems a bit confused about it itself
27syn region zshPOSIXString matchgroup=zshStringDelimiter start=+\$'+
28 \ end=+'+ contains=zshQuoted
29syn match zshJobSpec '%\(\d\+\|?\=\w\+\|[%+-]\)'
Bram Moolenaar071d4272004-06-13 20:20:40 +000030
Bram Moolenaarc81e5e72007-05-05 18:24:42 +000031syn keyword zshPrecommand noglob nocorrect exec command builtin - time
Bram Moolenaar071d4272004-06-13 20:20:40 +000032
Bram Moolenaarc81e5e72007-05-05 18:24:42 +000033syn keyword zshDelimiter do done
Bram Moolenaar071d4272004-06-13 20:20:40 +000034
Bram Moolenaarc81e5e72007-05-05 18:24:42 +000035syn keyword zshConditional if then elif else fi case in esac select
Bram Moolenaar071d4272004-06-13 20:20:40 +000036
Bram Moolenaare37d50a2008-08-06 17:06:04 +000037syn keyword zshRepeat while until repeat
38
39syn keyword zshRepeat for foreach nextgroup=zshVariable skipwhite
Bram Moolenaar071d4272004-06-13 20:20:40 +000040
Bram Moolenaarc81e5e72007-05-05 18:24:42 +000041syn keyword zshException always
Bram Moolenaar071d4272004-06-13 20:20:40 +000042
Bram Moolenaarc81e5e72007-05-05 18:24:42 +000043syn keyword zshKeyword function nextgroup=zshKSHFunction skipwhite
Bram Moolenaar071d4272004-06-13 20:20:40 +000044
Bram Moolenaarc81e5e72007-05-05 18:24:42 +000045syn match zshKSHFunction contained '\k\+'
46syn match zshFunction '^\s*\k\+\ze\s*()'
47
48syn match zshOperator '||\|&&\|;\|&!\='
49
50syn match zshRedir '\d\=\(<\|<>\|<<<\|<&\s*[0-9p-]\=\)'
51syn match zshRedir '\d\=\(>\|>>\|>&\s*[0-9p-]\=\|&>\|>>&\|&>>\)[|!]\='
52syn match zshRedir '|&\='
53
Bram Moolenaarc81e5e72007-05-05 18:24:42 +000054syn region zshHereDoc matchgroup=zshRedir
Bram Moolenaare37d50a2008-08-06 17:06:04 +000055 \ start='<\@<!<<\s*\z([^<]\S*\)'
56 \ end='^\z1\>'
57 \ contains=@zshSubst
Bram Moolenaarc81e5e72007-05-05 18:24:42 +000058syn region zshHereDoc matchgroup=zshRedir
Bram Moolenaare37d50a2008-08-06 17:06:04 +000059 \ start='<\@<!<<\s*\\\z(\S\+\)'
60 \ end='^\z1\>'
61 \ contains=@zshSubst
62syn region zshHereDoc matchgroup=zshRedir
63 \ start='<\@<!<<-\s*\\\=\z(\S\+\)'
64 \ end='^\s*\z1\>'
65 \ contains=@zshSubst
66syn region zshHereDoc matchgroup=zshRedir
67 \ start=+<\@<!<<\s*\(["']\)\z(\S\+\)\1+
68 \ end='^\z1\>'
69syn region zshHereDoc matchgroup=zshRedir
70 \ start=+<\@<!<<-\s*\(["']\)\z(\S\+\)\1+
Bram Moolenaarc81e5e72007-05-05 18:24:42 +000071 \ end='^\s*\z1\>'
72
Bram Moolenaare37d50a2008-08-06 17:06:04 +000073syn match zshVariable '\<\h\w*' contained
74
75syn match zshVariableDef '\<\h\w*\ze+\=='
Bram Moolenaarc81e5e72007-05-05 18:24:42 +000076" XXX: how safe is this?
Bram Moolenaare37d50a2008-08-06 17:06:04 +000077syn region zshVariableDef oneline
Bram Moolenaarc81e5e72007-05-05 18:24:42 +000078 \ start='\$\@<!\<\h\w*\[' end='\]\ze+\=='
79 \ contains=@zshSubst
80
81syn cluster zshDerefs contains=zshShortDeref,zshLongDeref,zshDeref
82
83if !exists("g:zsh_syntax_variables")
84 let s:zsh_syntax_variables = 'all'
85else
86 let s:zsh_syntax_variables = g:zsh_syntax_variables
Bram Moolenaar071d4272004-06-13 20:20:40 +000087endif
88
Bram Moolenaarc81e5e72007-05-05 18:24:42 +000089if s:zsh_syntax_variables =~ 'short\|all'
90 syn match zshShortDeref '\$[!#$*@?_-]\w\@!'
91 syn match zshShortDeref '\$[=^~]*[#+]*\d\+\>'
92endif
93
94if s:zsh_syntax_variables =~ 'long\|all'
95 syn match zshLongDeref '\$\%(ARGC\|argv\|status\|pipestatus\|CPUTYPE\|EGID\|EUID\|ERRNO\|GID\|HOST\|LINENO\|LOGNAME\)'
96 syn match zshLongDeref '\$\%(MACHTYPE\|OLDPWD OPTARG\|OPTIND\|OSTYPE\|PPID\|PWD\|RANDOM\|SECONDS\|SHLVL\|signals\)'
97 syn match zshLongDeref '\$\%(TRY_BLOCK_ERROR\|TTY\|TTYIDLE\|UID\|USERNAME\|VENDOR\|ZSH_NAME\|ZSH_VERSION\|REPLY\|reply\|TERM\)'
98endif
99
100if s:zsh_syntax_variables =~ 'all'
101 syn match zshDeref '\$[=^~]*[#+]*\h\w*\>'
102else
Bram Moolenaare37d50a2008-08-06 17:06:04 +0000103 syn match zshDeref transparent contains=NONE '\$[=^~]*[#+]*\h\w*\>'
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000104endif
105
106syn match zshCommands '\%(^\|\s\)[.:]\ze\s'
107syn keyword zshCommands alias autoload bg bindkey break bye cap cd
108 \ chdir clone comparguments compcall compctl
109 \ compdescribe compfiles compgroups compquote
110 \ comptags comptry compvalues continue dirs
111 \ disable disown echo echotc echoti emulate
112 \ enable eval exec exit export false fc fg
113 \ functions getcap getln getopts hash history
114 \ jobs kill let limit log logout popd print
115 \ printf pushd pushln pwd r read readonly
116 \ rehash return sched set setcap setopt shift
117 \ source stat suspend test times trap true
118 \ ttyctl type ulimit umask unalias unfunction
119 \ unhash unlimit unset unsetopt vared wait
120 \ whence where which zcompile zformat zftp zle
121 \ zmodload zparseopts zprof zpty zregexparse
122 \ zsocket zstyle ztcp
123
124syn keyword zshTypes float integer local typeset declare
125
126" XXX: this may be too much
127" syn match zshSwitches '\s\zs--\=[a-zA-Z0-9-]\+'
128
129syn match zshNumber '[+-]\=\<\d\+\>'
130syn match zshNumber '[+-]\=\<0x\x\+\>'
131syn match zshNumber '[+-]\=\<0\o\+\>'
132syn match zshNumber '[+-]\=\d\+#[-+]\=\w\+\>'
133syn match zshNumber '[+-]\=\d\+\.\d\+\>'
134
Bram Moolenaare37d50a2008-08-06 17:06:04 +0000135" TODO: $[...] is the same as $((...)), so add that as well.
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000136syn cluster zshSubst contains=zshSubst,zshOldSubst,zshMathSubst
137syn region zshSubst matchgroup=zshSubstDelim transparent
138 \ start='\$(' skip='\\)' end=')' contains=TOP
139syn region zshParentheses transparent start='(' skip='\\)' end=')'
140syn region zshMathSubst matchgroup=zshSubstDelim transparent
141 \ start='\$((' skip='\\)'
142 \ matchgroup=zshSubstDelim end='))'
143 \ contains=zshParentheses,@zshSubst,zshNumber,
144 \ @zshDerefs,zshString
145syn region zshBrackets contained transparent start='{' skip='\\}'
146 \ end='}'
147syn region zshSubst matchgroup=zshSubstDelim start='\${' skip='\\}'
Bram Moolenaare37d50a2008-08-06 17:06:04 +0000148 \ end='}' contains=@zshSubst,zshBrackets,zshQuoted,zshString
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000149syn region zshOldSubst matchgroup=zshSubstDelim start=+`+ skip=+\\`+
150 \ end=+`+ contains=TOP,zshOldSubst
151
Bram Moolenaare37d50a2008-08-06 17:06:04 +0000152syn sync minlines=50
153syn sync match zshHereDocSync grouphere NONE '<<-\=\s*\%(\\\=\S\+\|\(["']\)\S\+\1\)'
154syn sync match zshHereDocEndSync groupthere NONE '^\s*EO\a\+\>'
155
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000156hi def link zshTodo Todo
157hi def link zshComment Comment
158hi def link zshPreProc PreProc
159hi def link zshQuoted SpecialChar
160hi def link zshString String
161hi def link zshStringDelimiter zshString
162hi def link zshPOSIXString zshString
163hi def link zshJobSpec Special
164hi def link zshPrecommand Special
165hi def link zshDelimiter Keyword
166hi def link zshConditional Conditional
167hi def link zshException Exception
168hi def link zshRepeat Repeat
169hi def link zshKeyword Keyword
170hi def link zshFunction None
171hi def link zshKSHFunction zshFunction
172hi def link zshHereDoc String
173if 0
174 hi def link zshOperator Operator
175else
176 hi def link zshOperator None
177endif
178if 1
179 hi def link zshRedir Operator
180else
181 hi def link zshRedir None
182endif
183hi def link zshVariable None
Bram Moolenaare37d50a2008-08-06 17:06:04 +0000184hi def link zshVariableDef zshVariable
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000185hi def link zshDereferencing PreProc
186if s:zsh_syntax_variables =~ 'short\|all'
187 hi def link zshShortDeref zshDereferencing
188else
189 hi def link zshShortDeref None
190endif
191if s:zsh_syntax_variables =~ 'long\|all'
192 hi def link zshLongDeref zshDereferencing
193else
194 hi def link zshLongDeref None
195endif
196if s:zsh_syntax_variables =~ 'all'
197 hi def link zshDeref zshDereferencing
198else
199 hi def link zshDeref None
200endif
201hi def link zshCommands Keyword
202hi def link zshTypes Type
203hi def link zshSwitches Special
204hi def link zshNumber Number
205hi def link zshSubst PreProc
206hi def link zshMathSubst zshSubst
207hi def link zshOldSubst zshSubst
208hi def link zshSubstDelim zshSubst
209
Bram Moolenaar071d4272004-06-13 20:20:40 +0000210let b:current_syntax = "zsh"
211
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000212let &cpo = s:cpo_save
213unlet s:cpo_save