Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | " Vim syntax file |
Bram Moolenaar | c81e5e7 | 2007-05-05 18:24:42 +0000 | [diff] [blame] | 2 | " Language: Zsh shell script |
| 3 | " Maintainer: Nikolai Weibull <now@bitwi.se> |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 4 | " Latest Revision: 2008-07-17 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5 | |
Bram Moolenaar | c81e5e7 | 2007-05-05 18:24:42 +0000 | [diff] [blame] | 6 | if exists("b:current_syntax") |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7 | finish |
| 8 | endif |
| 9 | |
Bram Moolenaar | c81e5e7 | 2007-05-05 18:24:42 +0000 | [diff] [blame] | 10 | let s:cpo_save = &cpo |
| 11 | set cpo&vim |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 12 | |
Bram Moolenaar | 8c8de83 | 2008-06-24 22:58:06 +0000 | [diff] [blame] | 13 | setlocal iskeyword+=- |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 14 | |
Bram Moolenaar | c81e5e7 | 2007-05-05 18:24:42 +0000 | [diff] [blame] | 15 | syn keyword zshTodo contained TODO FIXME XXX NOTE |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 16 | |
Bram Moolenaar | c81e5e7 | 2007-05-05 18:24:42 +0000 | [diff] [blame] | 17 | syn region zshComment display oneline start='\%(^\|\s\)#' end='$' |
| 18 | \ contains=zshTodo,@Spell |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 19 | |
Bram Moolenaar | c81e5e7 | 2007-05-05 18:24:42 +0000 | [diff] [blame] | 20 | syn match zshPreProc '^\%1l#\%(!\|compdef\|autoload\).*$' |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 21 | |
Bram Moolenaar | c81e5e7 | 2007-05-05 18:24:42 +0000 | [diff] [blame] | 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\+\|[%+-]\)' |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 30 | |
Bram Moolenaar | c81e5e7 | 2007-05-05 18:24:42 +0000 | [diff] [blame] | 31 | syn keyword zshPrecommand noglob nocorrect exec command builtin - time |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 32 | |
Bram Moolenaar | c81e5e7 | 2007-05-05 18:24:42 +0000 | [diff] [blame] | 33 | syn keyword zshDelimiter do done |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 34 | |
Bram Moolenaar | c81e5e7 | 2007-05-05 18:24:42 +0000 | [diff] [blame] | 35 | syn keyword zshConditional if then elif else fi case in esac select |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 36 | |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 37 | syn keyword zshRepeat while until repeat |
| 38 | |
| 39 | syn keyword zshRepeat for foreach nextgroup=zshVariable skipwhite |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 40 | |
Bram Moolenaar | c81e5e7 | 2007-05-05 18:24:42 +0000 | [diff] [blame] | 41 | syn keyword zshException always |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 42 | |
Bram Moolenaar | c81e5e7 | 2007-05-05 18:24:42 +0000 | [diff] [blame] | 43 | syn keyword zshKeyword function nextgroup=zshKSHFunction skipwhite |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 44 | |
Bram Moolenaar | c81e5e7 | 2007-05-05 18:24:42 +0000 | [diff] [blame] | 45 | syn match zshKSHFunction contained '\k\+' |
| 46 | syn match zshFunction '^\s*\k\+\ze\s*()' |
| 47 | |
| 48 | syn match zshOperator '||\|&&\|;\|&!\=' |
| 49 | |
| 50 | syn match zshRedir '\d\=\(<\|<>\|<<<\|<&\s*[0-9p-]\=\)' |
| 51 | syn match zshRedir '\d\=\(>\|>>\|>&\s*[0-9p-]\=\|&>\|>>&\|&>>\)[|!]\=' |
| 52 | syn match zshRedir '|&\=' |
| 53 | |
Bram Moolenaar | c81e5e7 | 2007-05-05 18:24:42 +0000 | [diff] [blame] | 54 | syn region zshHereDoc matchgroup=zshRedir |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 55 | \ start='<\@<!<<\s*\z([^<]\S*\)' |
| 56 | \ end='^\z1\>' |
| 57 | \ contains=@zshSubst |
Bram Moolenaar | c81e5e7 | 2007-05-05 18:24:42 +0000 | [diff] [blame] | 58 | syn region zshHereDoc matchgroup=zshRedir |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 59 | \ start='<\@<!<<\s*\\\z(\S\+\)' |
| 60 | \ end='^\z1\>' |
| 61 | \ contains=@zshSubst |
| 62 | syn region zshHereDoc matchgroup=zshRedir |
| 63 | \ start='<\@<!<<-\s*\\\=\z(\S\+\)' |
| 64 | \ end='^\s*\z1\>' |
| 65 | \ contains=@zshSubst |
| 66 | syn region zshHereDoc matchgroup=zshRedir |
| 67 | \ start=+<\@<!<<\s*\(["']\)\z(\S\+\)\1+ |
| 68 | \ end='^\z1\>' |
| 69 | syn region zshHereDoc matchgroup=zshRedir |
| 70 | \ start=+<\@<!<<-\s*\(["']\)\z(\S\+\)\1+ |
Bram Moolenaar | c81e5e7 | 2007-05-05 18:24:42 +0000 | [diff] [blame] | 71 | \ end='^\s*\z1\>' |
| 72 | |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 73 | syn match zshVariable '\<\h\w*' contained |
| 74 | |
| 75 | syn match zshVariableDef '\<\h\w*\ze+\==' |
Bram Moolenaar | c81e5e7 | 2007-05-05 18:24:42 +0000 | [diff] [blame] | 76 | " XXX: how safe is this? |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 77 | syn region zshVariableDef oneline |
Bram Moolenaar | c81e5e7 | 2007-05-05 18:24:42 +0000 | [diff] [blame] | 78 | \ start='\$\@<!\<\h\w*\[' end='\]\ze+\==' |
| 79 | \ contains=@zshSubst |
| 80 | |
| 81 | syn cluster zshDerefs contains=zshShortDeref,zshLongDeref,zshDeref |
| 82 | |
| 83 | if !exists("g:zsh_syntax_variables") |
| 84 | let s:zsh_syntax_variables = 'all' |
| 85 | else |
| 86 | let s:zsh_syntax_variables = g:zsh_syntax_variables |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 87 | endif |
| 88 | |
Bram Moolenaar | c81e5e7 | 2007-05-05 18:24:42 +0000 | [diff] [blame] | 89 | if s:zsh_syntax_variables =~ 'short\|all' |
| 90 | syn match zshShortDeref '\$[!#$*@?_-]\w\@!' |
| 91 | syn match zshShortDeref '\$[=^~]*[#+]*\d\+\>' |
| 92 | endif |
| 93 | |
| 94 | if 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\)' |
| 98 | endif |
| 99 | |
| 100 | if s:zsh_syntax_variables =~ 'all' |
| 101 | syn match zshDeref '\$[=^~]*[#+]*\h\w*\>' |
| 102 | else |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 103 | syn match zshDeref transparent contains=NONE '\$[=^~]*[#+]*\h\w*\>' |
Bram Moolenaar | c81e5e7 | 2007-05-05 18:24:42 +0000 | [diff] [blame] | 104 | endif |
| 105 | |
| 106 | syn match zshCommands '\%(^\|\s\)[.:]\ze\s' |
| 107 | syn 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 | |
| 124 | syn 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 | |
| 129 | syn match zshNumber '[+-]\=\<\d\+\>' |
| 130 | syn match zshNumber '[+-]\=\<0x\x\+\>' |
| 131 | syn match zshNumber '[+-]\=\<0\o\+\>' |
| 132 | syn match zshNumber '[+-]\=\d\+#[-+]\=\w\+\>' |
| 133 | syn match zshNumber '[+-]\=\d\+\.\d\+\>' |
| 134 | |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 135 | " TODO: $[...] is the same as $((...)), so add that as well. |
Bram Moolenaar | c81e5e7 | 2007-05-05 18:24:42 +0000 | [diff] [blame] | 136 | syn cluster zshSubst contains=zshSubst,zshOldSubst,zshMathSubst |
| 137 | syn region zshSubst matchgroup=zshSubstDelim transparent |
| 138 | \ start='\$(' skip='\\)' end=')' contains=TOP |
| 139 | syn region zshParentheses transparent start='(' skip='\\)' end=')' |
| 140 | syn region zshMathSubst matchgroup=zshSubstDelim transparent |
| 141 | \ start='\$((' skip='\\)' |
| 142 | \ matchgroup=zshSubstDelim end='))' |
| 143 | \ contains=zshParentheses,@zshSubst,zshNumber, |
| 144 | \ @zshDerefs,zshString |
| 145 | syn region zshBrackets contained transparent start='{' skip='\\}' |
| 146 | \ end='}' |
| 147 | syn region zshSubst matchgroup=zshSubstDelim start='\${' skip='\\}' |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 148 | \ end='}' contains=@zshSubst,zshBrackets,zshQuoted,zshString |
Bram Moolenaar | c81e5e7 | 2007-05-05 18:24:42 +0000 | [diff] [blame] | 149 | syn region zshOldSubst matchgroup=zshSubstDelim start=+`+ skip=+\\`+ |
| 150 | \ end=+`+ contains=TOP,zshOldSubst |
| 151 | |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 152 | syn sync minlines=50 |
| 153 | syn sync match zshHereDocSync grouphere NONE '<<-\=\s*\%(\\\=\S\+\|\(["']\)\S\+\1\)' |
| 154 | syn sync match zshHereDocEndSync groupthere NONE '^\s*EO\a\+\>' |
| 155 | |
Bram Moolenaar | c81e5e7 | 2007-05-05 18:24:42 +0000 | [diff] [blame] | 156 | hi def link zshTodo Todo |
| 157 | hi def link zshComment Comment |
| 158 | hi def link zshPreProc PreProc |
| 159 | hi def link zshQuoted SpecialChar |
| 160 | hi def link zshString String |
| 161 | hi def link zshStringDelimiter zshString |
| 162 | hi def link zshPOSIXString zshString |
| 163 | hi def link zshJobSpec Special |
| 164 | hi def link zshPrecommand Special |
| 165 | hi def link zshDelimiter Keyword |
| 166 | hi def link zshConditional Conditional |
| 167 | hi def link zshException Exception |
| 168 | hi def link zshRepeat Repeat |
| 169 | hi def link zshKeyword Keyword |
| 170 | hi def link zshFunction None |
| 171 | hi def link zshKSHFunction zshFunction |
| 172 | hi def link zshHereDoc String |
| 173 | if 0 |
| 174 | hi def link zshOperator Operator |
| 175 | else |
| 176 | hi def link zshOperator None |
| 177 | endif |
| 178 | if 1 |
| 179 | hi def link zshRedir Operator |
| 180 | else |
| 181 | hi def link zshRedir None |
| 182 | endif |
| 183 | hi def link zshVariable None |
Bram Moolenaar | e37d50a | 2008-08-06 17:06:04 +0000 | [diff] [blame] | 184 | hi def link zshVariableDef zshVariable |
Bram Moolenaar | c81e5e7 | 2007-05-05 18:24:42 +0000 | [diff] [blame] | 185 | hi def link zshDereferencing PreProc |
| 186 | if s:zsh_syntax_variables =~ 'short\|all' |
| 187 | hi def link zshShortDeref zshDereferencing |
| 188 | else |
| 189 | hi def link zshShortDeref None |
| 190 | endif |
| 191 | if s:zsh_syntax_variables =~ 'long\|all' |
| 192 | hi def link zshLongDeref zshDereferencing |
| 193 | else |
| 194 | hi def link zshLongDeref None |
| 195 | endif |
| 196 | if s:zsh_syntax_variables =~ 'all' |
| 197 | hi def link zshDeref zshDereferencing |
| 198 | else |
| 199 | hi def link zshDeref None |
| 200 | endif |
| 201 | hi def link zshCommands Keyword |
| 202 | hi def link zshTypes Type |
| 203 | hi def link zshSwitches Special |
| 204 | hi def link zshNumber Number |
| 205 | hi def link zshSubst PreProc |
| 206 | hi def link zshMathSubst zshSubst |
| 207 | hi def link zshOldSubst zshSubst |
| 208 | hi def link zshSubstDelim zshSubst |
| 209 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 210 | let b:current_syntax = "zsh" |
| 211 | |
Bram Moolenaar | c81e5e7 | 2007-05-05 18:24:42 +0000 | [diff] [blame] | 212 | let &cpo = s:cpo_save |
| 213 | unlet s:cpo_save |