blob: eb19eba565eb3ce67afcabf98bb6ba31c3abb037 [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 Moolenaar8c8de832008-06-24 22:58:06 +00004" Latest Revision: 2007-06-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 Moolenaarc81e5e72007-05-05 18:24:42 +000037syn keyword zshRepeat for while until repeat foreach
Bram Moolenaar071d4272004-06-13 20:20:40 +000038
Bram Moolenaarc81e5e72007-05-05 18:24:42 +000039syn keyword zshException always
Bram Moolenaar071d4272004-06-13 20:20:40 +000040
Bram Moolenaarc81e5e72007-05-05 18:24:42 +000041syn keyword zshKeyword function nextgroup=zshKSHFunction skipwhite
Bram Moolenaar071d4272004-06-13 20:20:40 +000042
Bram Moolenaarc81e5e72007-05-05 18:24:42 +000043syn match zshKSHFunction contained '\k\+'
44syn match zshFunction '^\s*\k\+\ze\s*()'
45
46syn match zshOperator '||\|&&\|;\|&!\='
47
48syn match zshRedir '\d\=\(<\|<>\|<<<\|<&\s*[0-9p-]\=\)'
49syn match zshRedir '\d\=\(>\|>>\|>&\s*[0-9p-]\=\|&>\|>>&\|&>>\)[|!]\='
50syn match zshRedir '|&\='
51
52syn region zshHereDoc matchgroup=zshRedir start='<<\s*\z(\S*\)'
53 \ end='^\z1\>' contains=@zshSubst
54syn region zshHereDoc matchgroup=zshRedir start='<<-\s*\z(\S*\)'
55 \ end='^\s*\z1\>' contains=@zshSubst
56syn region zshHereDoc matchgroup=zshRedir
57 \ start=+<<\s*\(["']\)\z(\S*\)\1+ end='^\z1\>'
58syn region zshHereDoc matchgroup=zshRedir
59 \ start=+<<-\s*\(["']\)\z(\S*\)\1+
60 \ end='^\s*\z1\>'
61
62syn match zshVariable '\<\h\w*\ze+\=='
63" XXX: how safe is this?
64syn region zshVariable oneline
65 \ start='\$\@<!\<\h\w*\[' end='\]\ze+\=='
66 \ contains=@zshSubst
67
68syn cluster zshDerefs contains=zshShortDeref,zshLongDeref,zshDeref
69
70if !exists("g:zsh_syntax_variables")
71 let s:zsh_syntax_variables = 'all'
72else
73 let s:zsh_syntax_variables = g:zsh_syntax_variables
Bram Moolenaar071d4272004-06-13 20:20:40 +000074endif
75
Bram Moolenaarc81e5e72007-05-05 18:24:42 +000076if s:zsh_syntax_variables =~ 'short\|all'
77 syn match zshShortDeref '\$[!#$*@?_-]\w\@!'
78 syn match zshShortDeref '\$[=^~]*[#+]*\d\+\>'
79endif
80
81if s:zsh_syntax_variables =~ 'long\|all'
82 syn match zshLongDeref '\$\%(ARGC\|argv\|status\|pipestatus\|CPUTYPE\|EGID\|EUID\|ERRNO\|GID\|HOST\|LINENO\|LOGNAME\)'
83 syn match zshLongDeref '\$\%(MACHTYPE\|OLDPWD OPTARG\|OPTIND\|OSTYPE\|PPID\|PWD\|RANDOM\|SECONDS\|SHLVL\|signals\)'
84 syn match zshLongDeref '\$\%(TRY_BLOCK_ERROR\|TTY\|TTYIDLE\|UID\|USERNAME\|VENDOR\|ZSH_NAME\|ZSH_VERSION\|REPLY\|reply\|TERM\)'
85endif
86
87if s:zsh_syntax_variables =~ 'all'
88 syn match zshDeref '\$[=^~]*[#+]*\h\w*\>'
89else
90 syn match zshDeref transparent '\$[=^~]*[#+]*\h\w*\>'
91endif
92
93syn match zshCommands '\%(^\|\s\)[.:]\ze\s'
94syn keyword zshCommands alias autoload bg bindkey break bye cap cd
95 \ chdir clone comparguments compcall compctl
96 \ compdescribe compfiles compgroups compquote
97 \ comptags comptry compvalues continue dirs
98 \ disable disown echo echotc echoti emulate
99 \ enable eval exec exit export false fc fg
100 \ functions getcap getln getopts hash history
101 \ jobs kill let limit log logout popd print
102 \ printf pushd pushln pwd r read readonly
103 \ rehash return sched set setcap setopt shift
104 \ source stat suspend test times trap true
105 \ ttyctl type ulimit umask unalias unfunction
106 \ unhash unlimit unset unsetopt vared wait
107 \ whence where which zcompile zformat zftp zle
108 \ zmodload zparseopts zprof zpty zregexparse
109 \ zsocket zstyle ztcp
110
111syn keyword zshTypes float integer local typeset declare
112
113" XXX: this may be too much
114" syn match zshSwitches '\s\zs--\=[a-zA-Z0-9-]\+'
115
116syn match zshNumber '[+-]\=\<\d\+\>'
117syn match zshNumber '[+-]\=\<0x\x\+\>'
118syn match zshNumber '[+-]\=\<0\o\+\>'
119syn match zshNumber '[+-]\=\d\+#[-+]\=\w\+\>'
120syn match zshNumber '[+-]\=\d\+\.\d\+\>'
121
122syn cluster zshSubst contains=zshSubst,zshOldSubst,zshMathSubst
123syn region zshSubst matchgroup=zshSubstDelim transparent
124 \ start='\$(' skip='\\)' end=')' contains=TOP
125syn region zshParentheses transparent start='(' skip='\\)' end=')'
126syn region zshMathSubst matchgroup=zshSubstDelim transparent
127 \ start='\$((' skip='\\)'
128 \ matchgroup=zshSubstDelim end='))'
129 \ contains=zshParentheses,@zshSubst,zshNumber,
130 \ @zshDerefs,zshString
131syn region zshBrackets contained transparent start='{' skip='\\}'
132 \ end='}'
133syn region zshSubst matchgroup=zshSubstDelim start='\${' skip='\\}'
134 \ end='}' contains=@zshSubst,zshBrackets,zshQuoted
135syn region zshOldSubst matchgroup=zshSubstDelim start=+`+ skip=+\\`+
136 \ end=+`+ contains=TOP,zshOldSubst
137
138hi def link zshTodo Todo
139hi def link zshComment Comment
140hi def link zshPreProc PreProc
141hi def link zshQuoted SpecialChar
142hi def link zshString String
143hi def link zshStringDelimiter zshString
144hi def link zshPOSIXString zshString
145hi def link zshJobSpec Special
146hi def link zshPrecommand Special
147hi def link zshDelimiter Keyword
148hi def link zshConditional Conditional
149hi def link zshException Exception
150hi def link zshRepeat Repeat
151hi def link zshKeyword Keyword
152hi def link zshFunction None
153hi def link zshKSHFunction zshFunction
154hi def link zshHereDoc String
155if 0
156 hi def link zshOperator Operator
157else
158 hi def link zshOperator None
159endif
160if 1
161 hi def link zshRedir Operator
162else
163 hi def link zshRedir None
164endif
165hi def link zshVariable None
166hi def link zshDereferencing PreProc
167if s:zsh_syntax_variables =~ 'short\|all'
168 hi def link zshShortDeref zshDereferencing
169else
170 hi def link zshShortDeref None
171endif
172if s:zsh_syntax_variables =~ 'long\|all'
173 hi def link zshLongDeref zshDereferencing
174else
175 hi def link zshLongDeref None
176endif
177if s:zsh_syntax_variables =~ 'all'
178 hi def link zshDeref zshDereferencing
179else
180 hi def link zshDeref None
181endif
182hi def link zshCommands Keyword
183hi def link zshTypes Type
184hi def link zshSwitches Special
185hi def link zshNumber Number
186hi def link zshSubst PreProc
187hi def link zshMathSubst zshSubst
188hi def link zshOldSubst zshSubst
189hi def link zshSubstDelim zshSubst
190
Bram Moolenaar071d4272004-06-13 20:20:40 +0000191let b:current_syntax = "zsh"
192
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000193let &cpo = s:cpo_save
194unlet s:cpo_save