Runtime files update
[MacVim.git] / runtime / syntax / zsh.vim
blobeb19eba565eb3ce67afcabf98bb6ba31c3abb037
1 " Vim syntax file
2 " Language:         Zsh shell script
3 " Maintainer:       Nikolai Weibull <now@bitwi.se>
4 " Latest Revision:  2007-06-17
6 if exists("b:current_syntax")
7   finish
8 endif
10 let s:cpo_save = &cpo
11 set cpo&vim
13 setlocal iskeyword+=-
15 syn keyword zshTodo             contained TODO FIXME XXX NOTE
17 syn region  zshComment          display oneline start='\%(^\|\s\)#' end='$'
18                                 \ contains=zshTodo,@Spell
20 syn match   zshPreProc          '^\%1l#\%(!\|compdef\|autoload\).*$'
22 syn match   zshQuoted           '\\.'
23 syn region  zshString           matchgroup=zshStringDelimiter start=+"+ end=+"+
24                                 \ contains=zshQuoted,@zshDerefs,@zshSubst
25 syn region  zshString           matchgroup=zshStringDelimiter start=+'+ end=+'+
26 " XXX: This should probably be more precise, but Zsh seems a bit confused about it itself
27 syn region  zshPOSIXString      matchgroup=zshStringDelimiter start=+\$'+
28                                 \ end=+'+ contains=zshQuoted
29 syn match   zshJobSpec          '%\(\d\+\|?\=\w\+\|[%+-]\)'
31 syn keyword zshPrecommand       noglob nocorrect exec command builtin - time
33 syn keyword zshDelimiter        do done
35 syn keyword zshConditional      if then elif else fi case in esac select
37 syn keyword zshRepeat           for while until repeat foreach
39 syn keyword zshException        always
41 syn keyword zshKeyword          function nextgroup=zshKSHFunction skipwhite
43 syn match   zshKSHFunction      contained '\k\+'
44 syn match   zshFunction         '^\s*\k\+\ze\s*()'
46 syn match   zshOperator         '||\|&&\|;\|&!\='
48 syn match   zshRedir            '\d\=\(<\|<>\|<<<\|<&\s*[0-9p-]\=\)'
49 syn match   zshRedir            '\d\=\(>\|>>\|>&\s*[0-9p-]\=\|&>\|>>&\|&>>\)[|!]\='
50 syn match   zshRedir            '|&\='
52 syn region  zshHereDoc          matchgroup=zshRedir start='<<\s*\z(\S*\)'
53                                 \ end='^\z1\>' contains=@zshSubst
54 syn region  zshHereDoc          matchgroup=zshRedir start='<<-\s*\z(\S*\)'
55                                 \ end='^\s*\z1\>' contains=@zshSubst
56 syn region  zshHereDoc          matchgroup=zshRedir
57                                 \ start=+<<\s*\(["']\)\z(\S*\)\1+  end='^\z1\>'
58 syn region  zshHereDoc          matchgroup=zshRedir
59                                 \ start=+<<-\s*\(["']\)\z(\S*\)\1+
60                                 \ end='^\s*\z1\>'
62 syn match   zshVariable         '\<\h\w*\ze+\=='
63 " XXX: how safe is this?
64 syn region  zshVariable         oneline
65                                 \ start='\$\@<!\<\h\w*\[' end='\]\ze+\=='
66                                 \ contains=@zshSubst
68 syn cluster zshDerefs           contains=zshShortDeref,zshLongDeref,zshDeref
70 if !exists("g:zsh_syntax_variables")
71   let s:zsh_syntax_variables = 'all'
72 else
73   let s:zsh_syntax_variables = g:zsh_syntax_variables
74 endif
76 if s:zsh_syntax_variables =~ 'short\|all'
77   syn match zshShortDeref       '\$[!#$*@?_-]\w\@!'
78   syn match zshShortDeref       '\$[=^~]*[#+]*\d\+\>'
79 endif
81 if 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\)'
85 endif
87 if s:zsh_syntax_variables =~ 'all'
88   syn match zshDeref            '\$[=^~]*[#+]*\h\w*\>'
89 else
90   syn match zshDeref            transparent '\$[=^~]*[#+]*\h\w*\>'
91 endif
93 syn match   zshCommands         '\%(^\|\s\)[.:]\ze\s'
94 syn 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
111 syn keyword zshTypes            float integer local typeset declare
113 " XXX: this may be too much
114 " syn match   zshSwitches         '\s\zs--\=[a-zA-Z0-9-]\+'
116 syn match   zshNumber           '[+-]\=\<\d\+\>'
117 syn match   zshNumber           '[+-]\=\<0x\x\+\>'
118 syn match   zshNumber           '[+-]\=\<0\o\+\>'
119 syn match   zshNumber           '[+-]\=\d\+#[-+]\=\w\+\>'
120 syn match   zshNumber           '[+-]\=\d\+\.\d\+\>'
122 syn cluster zshSubst            contains=zshSubst,zshOldSubst,zshMathSubst
123 syn region  zshSubst            matchgroup=zshSubstDelim transparent
124                                 \ start='\$(' skip='\\)' end=')' contains=TOP
125 syn region  zshParentheses      transparent start='(' skip='\\)' end=')'
126 syn region  zshMathSubst        matchgroup=zshSubstDelim transparent
127                                 \ start='\$((' skip='\\)'
128                                 \ matchgroup=zshSubstDelim end='))'
129                                 \ contains=zshParentheses,@zshSubst,zshNumber,
130                                 \ @zshDerefs,zshString
131 syn region  zshBrackets         contained transparent start='{' skip='\\}'
132                                 \ end='}'
133 syn region  zshSubst            matchgroup=zshSubstDelim start='\${' skip='\\}'
134                                 \ end='}' contains=@zshSubst,zshBrackets,zshQuoted
135 syn region  zshOldSubst         matchgroup=zshSubstDelim start=+`+ skip=+\\`+
136                                 \ end=+`+ contains=TOP,zshOldSubst
138 hi def link zshTodo             Todo
139 hi def link zshComment          Comment
140 hi def link zshPreProc          PreProc
141 hi def link zshQuoted           SpecialChar
142 hi def link zshString           String
143 hi def link zshStringDelimiter  zshString
144 hi def link zshPOSIXString      zshString
145 hi def link zshJobSpec          Special
146 hi def link zshPrecommand       Special
147 hi def link zshDelimiter        Keyword
148 hi def link zshConditional      Conditional
149 hi def link zshException        Exception
150 hi def link zshRepeat           Repeat
151 hi def link zshKeyword          Keyword
152 hi def link zshFunction         None
153 hi def link zshKSHFunction      zshFunction
154 hi def link zshHereDoc          String
155 if 0
156   hi def link zshOperator         Operator
157 else
158   hi def link zshOperator         None
159 endif
160 if 1
161   hi def link zshRedir            Operator
162 else
163   hi def link zshRedir            None
164 endif
165 hi def link zshVariable         None
166 hi def link zshDereferencing    PreProc
167 if s:zsh_syntax_variables =~ 'short\|all'
168   hi def link zshShortDeref     zshDereferencing
169 else
170   hi def link zshShortDeref     None
171 endif
172 if s:zsh_syntax_variables =~ 'long\|all'
173   hi def link zshLongDeref      zshDereferencing
174 else
175   hi def link zshLongDeref      None
176 endif
177 if s:zsh_syntax_variables =~ 'all'
178   hi def link zshDeref          zshDereferencing
179 else
180   hi def link zshDeref          None
181 endif
182 hi def link zshCommands         Keyword
183 hi def link zshTypes            Type
184 hi def link zshSwitches         Special
185 hi def link zshNumber           Number
186 hi def link zshSubst            PreProc
187 hi def link zshMathSubst        zshSubst
188 hi def link zshOldSubst         zshSubst
189 hi def link zshSubstDelim       zshSubst
191 let b:current_syntax = "zsh"
193 let &cpo = s:cpo_save
194 unlet s:cpo_save