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> |
| 4 | " Latest Revision: 2006-08-06 |
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 | c81e5e7 | 2007-05-05 18:24:42 +0000 | [diff] [blame] | 13 | setlocal iskeyword=@,48-57,_,- |
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 | c81e5e7 | 2007-05-05 18:24:42 +0000 | [diff] [blame] | 37 | syn keyword zshRepeat for while until repeat foreach |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 38 | |
Bram Moolenaar | c81e5e7 | 2007-05-05 18:24:42 +0000 | [diff] [blame] | 39 | syn keyword zshException always |
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 zshKeyword function nextgroup=zshKSHFunction skipwhite |
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 match zshKSHFunction contained '\k\+' |
| 44 | syn match zshFunction '^\s*\k\+\ze\s*()' |
| 45 | |
| 46 | syn match zshOperator '||\|&&\|;\|&!\=' |
| 47 | |
| 48 | syn match zshRedir '\d\=\(<\|<>\|<<<\|<&\s*[0-9p-]\=\)' |
| 49 | syn match zshRedir '\d\=\(>\|>>\|>&\s*[0-9p-]\=\|&>\|>>&\|&>>\)[|!]\=' |
| 50 | syn match zshRedir '|&\=' |
| 51 | |
| 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\>' |
| 61 | |
| 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 |
| 67 | |
| 68 | syn cluster zshDerefs contains=zshShortDeref,zshLongDeref,zshDeref |
| 69 | |
| 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 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 74 | endif |
| 75 | |
Bram Moolenaar | c81e5e7 | 2007-05-05 18:24:42 +0000 | [diff] [blame] | 76 | if s:zsh_syntax_variables =~ 'short\|all' |
| 77 | syn match zshShortDeref '\$[!#$*@?_-]\w\@!' |
| 78 | syn match zshShortDeref '\$[=^~]*[#+]*\d\+\>' |
| 79 | endif |
| 80 | |
| 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 |
| 86 | |
| 87 | if s:zsh_syntax_variables =~ 'all' |
| 88 | syn match zshDeref '\$[=^~]*[#+]*\h\w*\>' |
| 89 | else |
| 90 | syn match zshDeref transparent '\$[=^~]*[#+]*\h\w*\>' |
| 91 | endif |
| 92 | |
| 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 |
| 110 | |
| 111 | syn 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 | |
| 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\+\>' |
| 121 | |
| 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 |
| 137 | |
| 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 |
| 190 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 191 | let b:current_syntax = "zsh" |
| 192 | |
Bram Moolenaar | c81e5e7 | 2007-05-05 18:24:42 +0000 | [diff] [blame] | 193 | let &cpo = s:cpo_save |
| 194 | unlet s:cpo_save |