comparison runtime/syntax/sh.vim @ 34:e170173ecb68 current-release

before ack base protocol.
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Wed, 26 Nov 2008 15:02:10 +0900
parents 76efa0be13f1
children c16898406ff2
comparison
equal deleted inserted replaced
33:7d0d8b831f5a 34:e170173ecb68
1 " Vim syntax file 1 " Vim syntax file
2 " Language: shell (sh) Korn shell (ksh) bash (sh) 2 " Language: shell (sh) Korn shell (ksh) bash (sh)
3 " Maintainer: Dr. Charles E. Campbell, Jr. <NdrOchipS@PcampbellAfamily.Mbiz> 3 " Maintainer: Dr. Charles E. Campbell, Jr. <NdrOchipS@PcampbellAfamily.Mbiz>
4 " Previous Maintainer: Lennart Schultz <Lennart.Schultz@ecmwf.int> 4 " Previous Maintainer: Lennart Schultz <Lennart.Schultz@ecmwf.int>
5 " Last Change: Dec 12, 2006 5 " Last Change: Jul 11, 2008
6 " Version: 89 6 " Version: 102
7 " URL: http://mysite.verizon.net/astronaut/vim/index.html#vimlinks_syntax 7 " URL: http://mysite.verizon.net/astronaut/vim/index.html#vimlinks_syntax
8 " 8 " For options and settings, please use: :help ft-sh-syntax
9 " Using the following VIM variables: {{{1
10 " g:is_bash if none of the previous three variables are
11 " defined, then if g:is_bash is set enhance with
12 " bash syntax highlighting
13 " g:is_kornshell if neither b:is_kornshell or b:is_bash is
14 " defined, then if g:is_kornshell is set
15 " enhance with kornshell/POSIX syntax highlighting
16 " g:is_posix this variable is the same as g:is_kornshell
17 " g:sh_fold_enabled if non-zero, syntax folding is enabled
18 " g:sh_minlines sets up syn sync minlines (dflt: 200)
19 " g:sh_maxlines sets up syn sync maxlines (dflt: 2x sh_minlines)
20 "
21 " This file includes many ideas from Éric Brunet (eric.brunet@ens.fr) 9 " This file includes many ideas from Éric Brunet (eric.brunet@ens.fr)
22 10
23 " For version 5.x: Clear all syntax items {{{1 11 " For version 5.x: Clear all syntax items {{{1
24 " For version 6.x: Quit when a syntax file was already loaded 12 " For version 6.x: Quit when a syntax file was already loaded
25 if version < 600 13 if version < 600
59 let g:sh_fold_enabled= 0 47 let g:sh_fold_enabled= 0
60 elseif g:sh_fold_enabled != 0 && !has("folding") 48 elseif g:sh_fold_enabled != 0 && !has("folding")
61 let g:sh_fold_enabled= 0 49 let g:sh_fold_enabled= 0
62 echomsg "Ignoring g:sh_fold_enabled=".g:sh_fold_enabled."; need to re-compile vim for +fold support" 50 echomsg "Ignoring g:sh_fold_enabled=".g:sh_fold_enabled."; need to re-compile vim for +fold support"
63 endif 51 endif
52 if !exists("s:sh_fold_functions")
53 let s:sh_fold_functions = 1
54 endif
55 if !exists("s:sh_fold_heredoc")
56 let s:sh_fold_heredoc = 2
57 endif
58 if !exists("s:sh_fold_ifdofor")
59 let s:sh_fold_ifdofor = 4
60 endif
64 if g:sh_fold_enabled && &fdm == "manual" 61 if g:sh_fold_enabled && &fdm == "manual"
65 set fdm=syntax 62 set fdm=syntax
66 endif 63 endif
67 64
68 " sh syntax is case sensitive {{{1 65 " sh syntax is case sensitive {{{1
69 syn case match 66 syn case match
70 67
71 " Clusters: contains=@... clusters {{{1 68 " Clusters: contains=@... clusters {{{1
72 "================================== 69 "==================================
73 syn cluster shCaseEsacList contains=shCaseStart,shCase,shCaseBar,shCaseIn,shComment,shDeref,shDerefSimple,shCaseCommandSub,shCaseExSingleQuote,shCaseSingleQuote,shCaseDoubleQuote,shCtrlSeq 70 syn cluster shErrorList contains=shDoError,shIfError,shInError,shCaseError,shEsacError,shCurlyError,shParenError,shTestError
71 if exists("b:is_kornshell")
72 syn cluster ErrorList add=shDTestError
73 endif
74 syn cluster shArithParenList contains=shArithmetic,shDeref,shDerefSimple,shEscape,shNumber,shOperator,shPosnParm,shExSingleQuote,shSingleQuote,shDoubleQuote,shStatement,shVariable,shAlias,shTest,shCtrlSeq,shSpecial,shParen
75 syn cluster shArithList contains=@shArithParenList,shParenError
76 syn cluster shCaseEsacList contains=shCaseStart,shCase,shCaseBar,shCaseIn,shComment,shDeref,shDerefSimple,shCaseCommandSub,shCaseExSingleQuote,shCaseSingleQuote,shCaseDoubleQuote,shCtrlSeq,@shErrorList,shStringSpecial
74 syn cluster shCaseList contains=@shCommandSubList,shCaseEsac,shColon,shCommandSub,shCommandSub,shComment,shDo,shEcho,shExpr,shFor,shHereDoc,shIf,shRedir,shSetList,shSource,shStatement,shVariable,shCtrlSeq 77 syn cluster shCaseList contains=@shCommandSubList,shCaseEsac,shColon,shCommandSub,shCommandSub,shComment,shDo,shEcho,shExpr,shFor,shHereDoc,shIf,shRedir,shSetList,shSource,shStatement,shVariable,shCtrlSeq
75 syn cluster shColonList contains=@shCaseList 78 syn cluster shColonList contains=@shCaseList
76 syn cluster shCommandSubList contains=shArithmetic,shDeref,shDerefSimple,shNumber,shOperator,shPosnParm,shExSingleQuote,shSingleQuote,shDoubleQuote,shStatement,shVariable,shSubSh,shAlias,shTest,shCtrlSeq 79 syn cluster shCommandSubList contains=shArithmetic,shDeref,shDerefSimple,shEscape,shNumber,shOperator,shPosnParm,shExSingleQuote,shSingleQuote,shDoubleQuote,shStatement,shVariable,shSubSh,shAlias,shTest,shCtrlSeq,shSpecial
77 syn cluster shCurlyList contains=shNumber,shComma,shDeref,shDerefSimple,shDerefSpecial 80 syn cluster shCurlyList contains=shNumber,shComma,shDeref,shDerefSimple,shDerefSpecial
78 syn cluster shDblQuoteList contains=shCommandSub,shDeref,shDerefSimple,shPosnParm,shExSingleQuote,shCtrlSeq,shSpecial 81 syn cluster shDblQuoteList contains=shCommandSub,shDeref,shDerefSimple,shPosnParm,shExSingleQuote,shCtrlSeq,shSpecial
79 syn cluster shDerefList contains=shDeref,shDerefSimple,shDerefVar,shDerefSpecial,shDerefWordError,shDerefPPS 82 syn cluster shDerefList contains=shDeref,shDerefSimple,shDerefVar,shDerefSpecial,shDerefWordError,shDerefPPS
80 syn cluster shDerefVarList contains=shDerefOp,shDerefVarArray,shDerefOpError 83 syn cluster shDerefVarList contains=shDerefOp,shDerefVarArray,shDerefOpError
81 syn cluster shEchoList contains=shArithmetic,shCommandSub,shDeref,shDerefSimple,shExpr,shExSingleQuote,shSingleQuote,shDoubleQuote,shCtrlSeq 84 syn cluster shEchoList contains=shArithmetic,shCommandSub,shDeref,shDerefSimple,shExpr,shExSingleQuote,shSingleQuote,shDoubleQuote,shCtrlSeq,shEchoQuote
82 syn cluster shExprList1 contains=shCharClass,shNumber,shOperator,shExSingleQuote,shSingleQuote,shDoubleQuote,shExpr,shDblBrace,shDeref,shDerefSimple,shCtrlSeq 85 syn cluster shExprList1 contains=shCharClass,shNumber,shOperator,shExSingleQuote,shSingleQuote,shDoubleQuote,shExpr,shDblBrace,shDeref,shDerefSimple,shCtrlSeq
83 syn cluster shExprList2 contains=@shExprList1,@shCaseList,shTest 86 syn cluster shExprList2 contains=@shExprList1,@shCaseList,shTest
84 syn cluster shFunctionList contains=@shCommandSubList,shCaseEsac,shColon,shCommandSub,shCommandSub,shComment,shDo,shEcho,shExpr,shFor,shHereDoc,shIf,shRedir,shSetList,shSource,shStatement,shVariable,shOperator,shFunctionStart,shCtrlSeq 87 syn cluster shFunctionList contains=@shCommandSubList,shCaseEsac,shColon,shCommandSub,shCommandSub,shComment,shDo,shEcho,shExpr,shFor,shHereDoc,shIf,shRedir,shSetList,shSource,shStatement,shVariable,shOperator,shCtrlSeq
85 if exists("b:is_kornshell") || exists("b:is_bash") 88 if exists("b:is_kornshell") || exists("b:is_bash")
89 syn cluster shFunctionList add=shRepeat
86 syn cluster shFunctionList add=shDblBrace,shDblParen 90 syn cluster shFunctionList add=shDblBrace,shDblParen
87 endif 91 endif
88 syn cluster shHereBeginList contains=@shCommandSubList 92 syn cluster shHereBeginList contains=@shCommandSubList
89 syn cluster shHereList contains=shBeginHere,shHerePayload 93 syn cluster shHereList contains=shBeginHere,shHerePayload
90 syn cluster shHereListDQ contains=shBeginHere,@shDblQuoteList,shHerePayload 94 syn cluster shHereListDQ contains=shBeginHere,@shDblQuoteList,shHerePayload
91 syn cluster shIdList contains=shCommandSub,shWrapLineOperator,shIdWhiteSpace,shDeref,shDerefSimple,shRedir,shExSingleQuote,shSingleQuote,shDoubleQuote,shExpr,shCtrlSeq 95 syn cluster shIdList contains=shCommandSub,shWrapLineOperator,shSetOption,shDeref,shDerefSimple,shRedir,shExSingleQuote,shSingleQuote,shDoubleQuote,shExpr,shCtrlSeq,shStringSpecial
92 syn cluster shLoopList contains=@shCaseList,shTestOpr,shExpr,shDblBrace,shConditional,shCaseEsac,shTest 96 syn cluster shLoopList contains=@shCaseList,shTestOpr,shExpr,shDblBrace,shConditional,shCaseEsac,shTest,@shErrorList,shSet
93 syn cluster shSubShList contains=@shCaseList,shOperator 97 syn cluster shSubShList contains=@shCaseList,shOperator
94 syn cluster shTestList contains=shCharClass,shComment,shCommandSub,shDeref,shDerefSimple,shDoubleQuote,shExpr,shExpr,shNumber,shOperator,shExSingleQuote,shSingleQuote,shTestOpr,shTest,shCtrlSeq 98 syn cluster shTestList contains=shCharClass,shComment,shCommandSub,shDeref,shDerefSimple,shDoubleQuote,shExpr,shExpr,shNumber,shOperator,shExSingleQuote,shSingleQuote,shTestOpr,shTest,shCtrlSeq
95 99
96 100
97 " Echo: {{{1 101 " Echo: {{{1
98 " ==== 102 " ====
99 " This one is needed INSIDE a CommandSub, so that `echo bla` be correct 103 " This one is needed INSIDE a CommandSub, so that `echo bla` be correct
100 syn region shEcho matchgroup=shStatement start="\<echo\>" skip="\\$" matchgroup=shOperator end="$" matchgroup=NONE end="[<>;&|()]"me=e-1 end="\d[<>]"me=e-2 end="#"me=e-1 contains=@shEchoList 104 syn region shEcho matchgroup=shStatement start="\<echo\>" skip="\\$" matchgroup=shOperator end="$" matchgroup=NONE end="[<>;&|()]"me=e-1 end="\d[<>]"me=e-2 end="#"me=e-1 contains=@shEchoList skipwhite nextgroup=shQuickComment
101 syn region shEcho matchgroup=shStatement start="\<print\>" skip="\\$" matchgroup=shOperator end="$" matchgroup=NONE end="[<>;&|()]"me=e-1 end="\d[<>]"me=e-2 end="#"me=e-1 contains=@shEchoList 105 syn region shEcho matchgroup=shStatement start="\<print\>" skip="\\$" matchgroup=shOperator end="$" matchgroup=NONE end="[<>;&|()]"me=e-1 end="\d[<>]"me=e-2 end="#"me=e-1 contains=@shEchoList skipwhite nextgroup=shQuickComment
102 106 syn match shEchoQuote contained '\%(\\\\\)*\\["`']'
103 " This must be after the strings, so that bla \" be correct 107
108 " This must be after the strings, so that ... \" will be correct
104 syn region shEmbeddedEcho contained matchgroup=shStatement start="\<print\>" skip="\\$" matchgroup=shOperator end="$" matchgroup=NONE end="[<>;&|`)]"me=e-1 end="\d[<>]"me=e-2 end="#"me=e-1 contains=shNumber,shExSingleQuote,shSingleQuote,shDeref,shDerefSimple,shSpecialVar,shOperator,shDoubleQuote,shCharClass,shCtrlSeq 109 syn region shEmbeddedEcho contained matchgroup=shStatement start="\<print\>" skip="\\$" matchgroup=shOperator end="$" matchgroup=NONE end="[<>;&|`)]"me=e-1 end="\d[<>]"me=e-2 end="#"me=e-1 contains=shNumber,shExSingleQuote,shSingleQuote,shDeref,shDerefSimple,shSpecialVar,shOperator,shDoubleQuote,shCharClass,shCtrlSeq
105 110
106 " Alias: {{{1 111 " Alias: {{{1
107 " ===== 112 " =====
108 if exists("b:is_kornshell") || exists("b:is_bash") 113 if exists("b:is_kornshell") || exists("b:is_bash")
123 if exists("b:is_kornshell") 128 if exists("b:is_kornshell")
124 syn match shDTestError "]]" 129 syn match shDTestError "]]"
125 endif 130 endif
126 syn match shTestError "]" 131 syn match shTestError "]"
127 132
128 " Options Interceptor: {{{1 133 " Options: {{{1
129 " ==================== 134 " ====================
130 syn match shOption "\s[\-+][a-zA-Z0-9]\+\>"ms=s+1 135 syn match shOption "\s\zs[-+][a-zA-Z0-9]\+\>"
131 syn match shOption "\s--[^ \t$`'"|]\+"ms=s+1 136 syn match shOption "\s\zs--[^ \t$`'"|]\+"
132 137
133 " File Redirection Highlighted As Operators: {{{1 138 " File Redirection Highlighted As Operators: {{{1
134 "=========================================== 139 "===========================================
135 syn match shRedir "\d\=>\(&[-0-9]\)\=" 140 syn match shRedir "\d\=>\(&[-0-9]\)\="
136 syn match shRedir "\d\=>>-\=" 141 syn match shRedir "\d\=>>-\="
138 syn match shRedir "\d<<-\=" 143 syn match shRedir "\d<<-\="
139 144
140 " Operators: {{{1 145 " Operators: {{{1
141 " ========== 146 " ==========
142 syn match shOperator "<<\|>>" contained 147 syn match shOperator "<<\|>>" contained
143 syn match shOperator "[!&;|]" 148 syn match shOperator "[!&;|]" contained
144 syn match shOperator "\[[[^:]\|\]]" 149 syn match shOperator "\[[[^:]\|\]]" contained
145 syn match shOperator "!\==" skipwhite nextgroup=shPattern 150 syn match shOperator "!\==" skipwhite nextgroup=shPattern
146 syn match shPattern "\<\S\+\())\)\@=" contained contains=shExSingleQuote,shSingleQuote,shDoubleQuote,shDeref 151 syn match shPattern "\<\S\+\())\)\@=" contained contains=shExSingleQuote,shSingleQuote,shDoubleQuote,shDeref
147 152
148 " Subshells: {{{1 153 " Subshells: {{{1
149 " ========== 154 " ==========
170 " ========================= 175 " =========================
171 syn match shCharClass contained "\[:\(backspace\|escape\|return\|xdigit\|alnum\|alpha\|blank\|cntrl\|digit\|graph\|lower\|print\|punct\|space\|upper\|tab\):\]" 176 syn match shCharClass contained "\[:\(backspace\|escape\|return\|xdigit\|alnum\|alpha\|blank\|cntrl\|digit\|graph\|lower\|print\|punct\|space\|upper\|tab\):\]"
172 177
173 " Loops: do, if, while, until {{{1 178 " Loops: do, if, while, until {{{1
174 " ====== 179 " ======
175 if g:sh_fold_enabled 180 if (g:sh_fold_enabled % (s:sh_fold_ifdofor * 2))/s:sh_fold_ifdofor
176 syn region shDo fold transparent matchgroup=shConditional start="\<do\>" matchgroup=shConditional end="\<done\>" contains=@shLoopList 181 syn region shDo fold transparent matchgroup=shConditional start="\<do\>" matchgroup=shConditional end="\<done\>" contains=@shLoopList
177 syn region shIf fold transparent matchgroup=shConditional start="\<if\>" matchgroup=shConditional end="\<;\_s*then\>" end="\<fi\>" contains=@shLoopList,shDblBrace,shDblParen,shFunctionKey 182 syn region shIf fold transparent matchgroup=shConditional start="\<if\_s" matchgroup=shConditional end="\<;\_s*then\>" end="\<fi\>" contains=@shLoopList,shDblBrace,shDblParen,shFunctionKey
178 syn region shFor fold matchgroup=shLoop start="\<for\>" end="\<in\>" end="\<do\>"me=e-2 contains=@shLoopList,shDblParen skipwhite nextgroup=shCurlyIn 183 syn region shFor fold matchgroup=shLoop start="\<for\_s" end="\<in\_s" end="\<do\>"me=e-2 contains=@shLoopList,shDblParen skipwhite nextgroup=shCurlyIn
179 else 184 else
180 syn region shDo transparent matchgroup=shConditional start="\<do\>" matchgroup=shConditional end="\<done\>" contains=@shLoopList 185 syn region shDo transparent matchgroup=shConditional start="\<do\>" matchgroup=shConditional end="\<done\>" contains=@shLoopList
181 syn region shIf transparent matchgroup=shConditional start="\<if\>" matchgroup=shConditional end="\<;\_s*then\>" end="\<fi\>" contains=@shLoopList,shDblBrace,shDblParen,shFunctionKey 186 syn region shIf transparent matchgroup=shConditional start="\<if\_s" matchgroup=shConditional end="\<;\_s*then\>" end="\<fi\>" contains=@shLoopList,shDblBrace,shDblParen,shFunctionKey
182 syn region shFor matchgroup=shLoop start="\<for\>" end="\<in\>" end="\<do\>"me=e-2 contains=@shLoopList,shDblParen skipwhite nextgroup=shCurlyIn 187 syn region shFor matchgroup=shLoop start="\<for\_s" end="\<in\>" end="\<do\>"me=e-2 contains=@shLoopList,shDblParen skipwhite nextgroup=shCurlyIn
183 endif 188 endif
184 if exists("b:is_kornshell") || exists("b:is_bash") 189 if exists("b:is_kornshell") || exists("b:is_bash")
185 syn cluster shCaseList add=shRepeat 190 syn cluster shCaseList add=shRepeat
186 syn region shRepeat matchgroup=shLoop start="\<while\>" end="\<in\>" end="\<do\>"me=e-2 contains=@shLoopList,shDblParen,shDblBrace 191 syn cluster shFunctionList add=shRepeat
187 syn region shRepeat matchgroup=shLoop start="\<until\>" end="\<in\>" end="\<do\>"me=e-2 contains=@shLoopList,shDblParen,shDblBrace 192 syn region shRepeat matchgroup=shLoop start="\<while\_s" end="\<in\_s" end="\<do\>"me=e-2 contains=@shLoopList,shDblParen,shDblBrace
188 syn region shCaseEsac matchgroup=shConditional start="\<select\>" matchgroup=shConditional end="\<in\>" end="\<do\>" contains=@shLoopList 193 syn region shRepeat matchgroup=shLoop start="\<until\_s" end="\<in\_s" end="\<do\>"me=e-2 contains=@shLoopList,shDblParen,shDblBrace
189 else 194 syn region shCaseEsac matchgroup=shConditional start="\<select\s" matchgroup=shConditional end="\<in\>" end="\<do\>" contains=@shLoopList
190 syn region shRepeat matchgroup=shLoop start="\<while\>" end="\<do\>"me=e-2 contains=@shLoopList 195 else
191 syn region shRepeat matchgroup=shLoop start="\<until\>" end="\<do\>"me=e-2 contains=@shLoopList 196 syn region shRepeat matchgroup=shLoop start="\<while\_s" end="\<do\>"me=e-2 contains=@shLoopList
197 syn region shRepeat matchgroup=shLoop start="\<until\_s" end="\<do\>"me=e-2 contains=@shLoopList
192 endif 198 endif
193 syn region shCurlyIn contained matchgroup=Delimiter start="{" end="}" contains=@shCurlyList 199 syn region shCurlyIn contained matchgroup=Delimiter start="{" end="}" contains=@shCurlyList
194 syn match shComma contained "," 200 syn match shComma contained ","
195 201
196 " Case: case...esac {{{1 202 " Case: case...esac {{{1
197 " ==== 203 " ====
198 syn match shCaseBar contained skipwhite "[^|"`'()]\{-}|"hs=e nextgroup=shCase,shCaseStart,shCaseBar,shComment,shCaseExSingleQuote,shCaseSingleQuote,shCaseDoubleQuote 204 syn match shCaseBar contained skipwhite "\(^\|[^\\]\)\(\\\\\)*\zs|" nextgroup=shCase,shCaseStart,shCaseBar,shComment,shCaseExSingleQuote,shCaseSingleQuote,shCaseDoubleQuote
199 syn match shCaseStart contained skipwhite skipnl "(" nextgroup=shCase,shCaseBar 205 syn match shCaseStart contained skipwhite skipnl "(" nextgroup=shCase,shCaseBar
200 syn region shCase contained skipwhite skipnl matchgroup=shSnglCase start="\([^#$()'" \t]\|\\.\)\{-})"ms=s,hs=e end=";;" end="esac"me=s-1 contains=@shCaseList nextgroup=shCaseStart,shCase,shComment 206 syn region shCase contained skipwhite skipnl matchgroup=shSnglCase start="\%(\\.\|[^#$()'" \t]\)\{-}\zs)" end=";;" end="esac"me=s-1 contains=@shCaseList nextgroup=shCaseStart,shCase,shComment
201 if g:sh_fold_enabled 207 if (g:sh_fold_enabled % (s:sh_fold_ifdofor * 2))/s:sh_fold_ifdofor
202 syn region shCaseEsac fold matchgroup=shConditional start="\<case\>" end="\<esac\>" contains=@shCaseEsacList 208 syn region shCaseEsac fold matchgroup=shConditional start="\<case\>" end="\<esac\>" contains=@shCaseEsacList
203 else 209 else
204 syn region shCaseEsac matchgroup=shConditional start="\<case\>" end="\<esac\>" contains=@shCaseEsacList 210 syn region shCaseEsac matchgroup=shConditional start="\<case\>" end="\<esac\>" contains=@shCaseEsacList
205 endif 211 endif
206 syn keyword shCaseIn contained skipwhite skipnl in nextgroup=shCase,shCaseStart,shCaseBar,shComment,shCaseExSingleQuote,shCaseSingleQuote,shCaseDoubleQuote 212 syn keyword shCaseIn contained skipwhite skipnl in nextgroup=shCase,shCaseStart,shCaseBar,shComment,shCaseExSingleQuote,shCaseSingleQuote,shCaseDoubleQuote
215 221
216 " Misc: {{{1 222 " Misc: {{{1
217 "====== 223 "======
218 syn match shWrapLineOperator "\\$" 224 syn match shWrapLineOperator "\\$"
219 syn region shCommandSub start="`" skip="\\\\\|\\." end="`" contains=@shCommandSubList 225 syn region shCommandSub start="`" skip="\\\\\|\\." end="`" contains=@shCommandSubList
226 syn match shEscape contained '\\.'
220 227
221 " $() and $(()): {{{1 228 " $() and $(()): {{{1
222 " $(..) is not supported by sh (Bourne shell). However, apparently 229 " $(..) is not supported by sh (Bourne shell). However, apparently
223 " some systems (HP?) have as their /bin/sh a (link to) Korn shell 230 " some systems (HP?) have as their /bin/sh a (link to) Korn shell
224 " (ie. Posix compliant shell). /bin/ksh should work for those 231 " (ie. Posix compliant shell). /bin/ksh should work for those
225 " systems too, however, so the following syntax will flag $(..) as 232 " systems too, however, so the following syntax will flag $(..) as
226 " an Error under /bin/sh. By consensus of vimdev'ers! 233 " an Error under /bin/sh. By consensus of vimdev'ers!
227 if exists("b:is_kornshell") || exists("b:is_bash") 234 if exists("b:is_kornshell") || exists("b:is_bash")
228 syn region shCommandSub matchgroup=shCmdSubRegion start="\$(" skip='\\\\\|\\.' end=")" contains=@shCommandSubList 235 syn region shCommandSub matchgroup=shCmdSubRegion start="\$(" skip='\\\\\|\\.' end=")" contains=@shCommandSubList
229 syn region shArithmetic matchgroup=shArithRegion start="\$((" skip='\\\\\|\\.' end="))" contains=@shCommandSubList 236 syn region shArithmetic matchgroup=shArithRegion start="\$((" skip='\\\\\|\\.' end="))" contains=@shArithList
230 syn match shSkipInitWS contained "^\s\+" 237 syn match shSkipInitWS contained "^\s\+"
231 else 238 else
232 syn region shCommandSub matchgroup=Error start="\$(" end=")" contains=@shCommandSubList 239 syn region shCommandSub matchgroup=Error start="\$(" end=")" contains=@shCommandSubList
233 endif 240 endif
234 241
263 else 270 else
264 syn region shExSingleQuote matchGroup=Error start=+\$'+ skip=+\\\\\|\\.+ end=+'+ contains=shStringSpecial 271 syn region shExSingleQuote matchGroup=Error start=+\$'+ skip=+\\\\\|\\.+ end=+'+ contains=shStringSpecial
265 endif 272 endif
266 syn region shSingleQuote matchgroup=shOperator start=+'+ end=+'+ contains=shStringSpecial,@Spell 273 syn region shSingleQuote matchgroup=shOperator start=+'+ end=+'+ contains=shStringSpecial,@Spell
267 syn region shDoubleQuote matchgroup=shOperator start=+"+ skip=+\\"+ end=+"+ contains=@shDblQuoteList,shStringSpecial,@Spell 274 syn region shDoubleQuote matchgroup=shOperator start=+"+ skip=+\\"+ end=+"+ contains=@shDblQuoteList,shStringSpecial,@Spell
268 syn match shStringSpecial "[^[:print:]]" contained 275 syn match shStringSpecial "[^[:print:] \t]" contained
269 syn match shStringSpecial "\%(\\\\\)*\\[\\"'`$()#]" 276 syn match shStringSpecial "\%(\\\\\)*\\[\\"'`$()#]"
270 syn match shSpecial "[^\\]\zs\%(\\\\\)*\\[\\"'`$()#]" 277 syn match shSpecial "[^\\]\zs\%(\\\\\)*\\[\\"'`$()#]"
271 syn match shSpecial "^\%(\\\\\)*\\[\\"'`$()#]" 278 syn match shSpecial "^\%(\\\\\)*\\[\\"'`$()#]"
272 279
273 " Comments: {{{1 280 " Comments: {{{1
274 "========== 281 "==========
275 syn cluster shCommentGroup contains=shTodo,@Spell 282 syn cluster shCommentGroup contains=shTodo,@Spell
276 syn keyword shTodo contained COMBAK FIXME TODO XXX 283 syn keyword shTodo contained COMBAK FIXME TODO XXX
277 syn match shComment "^\s*\zs#.*$" contains=@shCommentGroup 284 syn match shComment "^\s*\zs#.*$" contains=@shCommentGroup
278 syn match shComment "#.*$" contains=@shCommentGroup 285 syn match shComment "\s\zs#.*$" contains=@shCommentGroup
286 syn match shQuickComment contained "#.*$"
279 287
280 " Here Documents: {{{1 288 " Here Documents: {{{1
281 " ========================================= 289 " =========================================
282 if version < 600 290 if version < 600
283 syn region shHereDoc matchgroup=shRedir start="<<\s*\**END[a-zA-Z_0-9]*\**" matchgroup=shRedir end="^END[a-zA-Z_0-9]*$" contains=@shDblQuoteList 291 syn region shHereDoc matchgroup=shRedir start="<<\s*\**END[a-zA-Z_0-9]*\**" matchgroup=shRedir end="^END[a-zA-Z_0-9]*$" contains=@shDblQuoteList
285 syn region shHereDoc matchgroup=shRedir start="<<\s*\**EOF\**" matchgroup=shRedir end="^EOF$" contains=@shDblQuoteList 293 syn region shHereDoc matchgroup=shRedir start="<<\s*\**EOF\**" matchgroup=shRedir end="^EOF$" contains=@shDblQuoteList
286 syn region shHereDoc matchgroup=shRedir start="<<-\s*\**EOF\**" matchgroup=shRedir end="^\s*EOF$" contains=@shDblQuoteList 294 syn region shHereDoc matchgroup=shRedir start="<<-\s*\**EOF\**" matchgroup=shRedir end="^\s*EOF$" contains=@shDblQuoteList
287 syn region shHereDoc matchgroup=shRedir start="<<\s*\**\.\**" matchgroup=shRedir end="^\.$" contains=@shDblQuoteList 295 syn region shHereDoc matchgroup=shRedir start="<<\s*\**\.\**" matchgroup=shRedir end="^\.$" contains=@shDblQuoteList
288 syn region shHereDoc matchgroup=shRedir start="<<-\s*\**\.\**" matchgroup=shRedir end="^\s*\.$" contains=@shDblQuoteList 296 syn region shHereDoc matchgroup=shRedir start="<<-\s*\**\.\**" matchgroup=shRedir end="^\s*\.$" contains=@shDblQuoteList
289 297
290 elseif g:sh_fold_enabled 298 elseif (g:sh_fold_enabled % (s:sh_fold_heredoc * 2))/s:sh_fold_heredoc
291 syn region shHereDoc matchgroup=shRedir fold start="<<\s*\z(\S*\)" matchgroup=shRedir end="^\z1\s*$" contains=@shDblQuoteList 299 syn region shHereDoc matchgroup=shRedir fold start="<<\s*\z(\S*\)" matchgroup=shRedir end="^\z1\s*$" contains=@shDblQuoteList
292 syn region shHereDoc matchgroup=shRedir fold start="<<\s*\"\z(\S*\)\"" matchgroup=shRedir end="^\z1\s*$" 300 syn region shHereDoc matchgroup=shRedir fold start="<<\s*\"\z(\S*\)\"" matchgroup=shRedir end="^\z1\s*$"
293 syn region shHereDoc matchgroup=shRedir fold start="<<\s*'\z(\S*\)'" matchgroup=shRedir end="^\z1\s*$" 301 syn region shHereDoc matchgroup=shRedir fold start="<<\s*'\z(\S*\)'" matchgroup=shRedir end="^\z1\s*$"
294 syn region shHereDoc matchgroup=shRedir fold start="<<-\s*\z(\S*\)" matchgroup=shRedir end="^\s*\z1\s*$" contains=@shDblQuoteList 302 syn region shHereDoc matchgroup=shRedir fold start="<<-\s*\z(\S*\)" matchgroup=shRedir end="^\s*\z1\s*$" contains=@shDblQuoteList
295 syn region shHereDoc matchgroup=shRedir fold start="<<-\s*\"\z(\S*\)\"" matchgroup=shRedir end="^\s*\z1\s*$" 303 syn region shHereDoc matchgroup=shRedir fold start="<<-\s*\"\z(\S*\)\"" matchgroup=shRedir end="^\s*\z1\s*$"
324 syn match shRedir "<<<" 332 syn match shRedir "<<<"
325 endif 333 endif
326 334
327 " Identifiers: {{{1 335 " Identifiers: {{{1
328 "============= 336 "=============
329 syn match shVariable "\<\([bwglsav]:\)\=[a-zA-Z0-9.!@_%+,]*\ze=" nextgroup=shSetIdentifier 337 syn match shSetOption "\s\zs[-+][a-zA-Z0-9]\+\>" contained
330 syn match shIdWhiteSpace contained "\s" 338 syn match shVariable "\<\([bwglsav]:\)\=[a-zA-Z0-9.!@_%+,]*\ze=" nextgroup=shSetIdentifier
331 syn match shSetIdentifier contained "=" nextgroup=shPattern,shDeref,shDerefSimple,shDoubleQuote,shSingleQuote,shExSingleQuote 339 syn match shSetIdentifier "=" contained nextgroup=shPattern,shDeref,shDerefSimple,shDoubleQuote,shSingleQuote,shExSingleQuote
332 if exists("b:is_bash") 340 if exists("b:is_bash")
333 syn region shSetList matchgroup=shSet start="\<\(declare\|typeset\|local\|export\|unset\)\>\ze[^/]" end="$" matchgroup=shOperator end="\ze[|);&]"me=e-1 matchgroup=NONE end="#\|="me=e-1 contains=@shIdList 341 syn region shSetList oneline matchgroup=shSet start="\<\(declare\|typeset\|local\|export\|unset\)\>\ze[^/]" end="$" matchgroup=shOperator end="\ze[}|);&]" matchgroup=NONE end="\ze#\|=" contains=@shIdList
334 syn region shSetList matchgroup=shSet start="\<set\>[^/]"me=e-1 end="$" end="\\ze[|)]" matchgroup=shOperator end="\ze[|);&]"me=e-1 matchgroup=NONE end="[#=]"me=e-1 contains=@shIdList 342 syn region shSetList oneline matchgroup=shSet start="\<set\>\ze[^/]" end="\ze[;|)]\|$" matchgroup=shOperator end="\ze[}|);&]" matchgroup=NONE end="\ze[#=]" contains=@shIdList
335 syn match shSet "\<\(declare\|typeset\|local\|export\|set\|unset\)\>"
336 elseif exists("b:is_kornshell") 343 elseif exists("b:is_kornshell")
337 syn region shSetList matchgroup=shSet start="\<\(typeset\|export\|unset\)\>\ze[^/]" end="$" matchgroup=shOperator end="\ze[|);&]"me=e-1 matchgroup=NONE end="[#=]"me=e-1 contains=@shIdList 344 syn region shSetList oneline matchgroup=shSet start="\<\(typeset\|export\|unset\)\>\ze[^/]" end="$" matchgroup=shOperator end="\ze[}|);&]" matchgroup=NONE end="\ze[#=]" contains=@shIdList
338 syn region shSetList matchgroup=shSet start="\<set\>\ze[^/]" end="$\|\ze[})]" matchgroup=shOperator end="\ze[|);&]"me=e-1 matchgroup=NONE end="[#=]"me=e-1 contains=@shIdList 345 syn region shSetList oneline matchgroup=shSet start="\<set\>\ze[^/]" end="$" matchgroup=shOperator end="\ze[}|);&]" matchgroup=NONE end="\ze[#=]" contains=@shIdList
339 syn match shSet "\<\(typeset\|set\|export\|unset\)\>" 346 else
340 else 347 syn region shSetList oneline matchgroup=shSet start="\<\(set\|export\|unset\)\>\ze[^/]" end="$" matchgroup=shOperator end="\ze[}|);&]" matchgroup=NONE end="\ze[#=]" contains=@shIdList
341 syn region shSetList matchgroup=shSet start="\<\(set\|export\|unset\)\>\ze[^/]" end="$\|\ze[|)]" matchgroup=shOperator end="\ze[|);&]" matchgroup=NONE end="[#=]"me=e-1 contains=@shIdList
342 syn match shStatement "\<\(set\|export\|unset\)\>"
343 endif 348 endif
344 349
345 " Functions: {{{1 350 " Functions: {{{1
346 syn keyword shFunctionKey function skipwhite skipnl nextgroup=shFunctionTwo 351 if !exists("g:is_posix")
347 " COMBAK -- look at bash09. function foo() (line#35) is folding 38 lines. Not being terminated properly 352 syn keyword shFunctionKey function skipwhite skipnl nextgroup=shFunctionTwo
348 "syn match shFunctionStart "{" contained 353 endif
349 if g:sh_fold_enabled 354
350 syn region shFunctionOne transparent fold start="^\s*\h\w*\s*()\_s*\ze{" matchgroup=shFunctionStart end="}" contains=@shFunctionList skipwhite skipnl nextgroup=shFunctionStart 355 if exists("b:is_bash")
351 syn region shFunctionTwo transparent fold start="\h\w*\s*\%(()\)\=\_s*\ze{" matchgroup=shFunctionStart end="}" contains=shFunctionKey,@shFunctionList contained skipwhite skipnl nextgroup=shFunctionStart 356 if (g:sh_fold_enabled % (s:sh_fold_functions * 2))/s:sh_fold_functions
352 else 357 syn region shFunctionOne fold matchgroup=shFunction start="^\s*\h[-a-zA-Z_0-9]*\s*()\_s*{" end="}" contains=@shFunctionList skipwhite skipnl nextgroup=shFunctionStart,shQuickComment
353 syn region shFunctionOne transparent start="^\s*\h\w*\s*()\_s*\ze{" matchgroup=shFunctionStart end="}" contains=@shFunctionList 358 syn region shFunctionTwo fold matchgroup=shFunction start="\h[-a-zA-Z_0-9]*\s*\%(()\)\=\_s*{" end="}" contains=shFunctionKey,@shFunctionList contained skipwhite skipnl nextgroup=shFunctionStart,shQuickComment
354 syn region shFunctionTwo transparent start="\h\w*\s*\%(()\)\=\_s*\ze{" matchgroup=shFunctionStart end="}" contains=shFunctionKey,@shFunctionList contained 359 else
360 syn region shFunctionOne matchgroup=shFunction start="^\s*\h[-a-zA-Z_0-9]*\s*()\_s*{" end="}" contains=@shFunctionList
361 syn region shFunctionTwo matchgroup=shFunction start="\h[-a-zA-Z_0-9]*\s*\%(()\)\=\_s*{" end="}" contains=shFunctionKey,@shFunctionList contained
362 endif
363 else
364 if (g:sh_fold_enabled % (s:sh_fold_functions * 2))/s:sh_fold_functions
365 syn region shFunctionOne fold matchgroup=shFunction start="^\s*\h\w*\s*()\_s*{" end="}" contains=@shFunctionList skipwhite skipnl nextgroup=shFunctionStart,shQuickComment
366 syn region shFunctionTwo fold matchgroup=shFunction start="\h\w*\s*\%(()\)\=\_s*{" end="}" contains=shFunctionKey,@shFunctionList contained skipwhite skipnl nextgroup=shFunctionStart,shQuickComment
367 else
368 syn region shFunctionOne matchgroup=shFunction start="^\s*\h\w*\s*()\_s*{" end="}" contains=@shFunctionList
369 syn region shFunctionTwo matchgroup=shFunction start="\h\w*\s*\%(()\)\=\_s*{" end="}" contains=shFunctionKey,@shFunctionList contained
370 endif
355 endif 371 endif
356 372
357 " Parameter Dereferencing: {{{1 373 " Parameter Dereferencing: {{{1
358 " ======================== 374 " ========================
359 syn match shDerefSimple "\$\%(\h\w*\|\d\)" 375 syn match shDerefSimple "\$\%(\h\w*\|\d\)"
361 syn match shDerefWordError "[^}$[]" contained 377 syn match shDerefWordError "[^}$[]" contained
362 syn match shDerefSimple "\$[-#*@!?]" 378 syn match shDerefSimple "\$[-#*@!?]"
363 syn match shDerefSimple "\$\$" 379 syn match shDerefSimple "\$\$"
364 if exists("b:is_bash") || exists("b:is_kornshell") 380 if exists("b:is_bash") || exists("b:is_kornshell")
365 syn region shDeref matchgroup=PreProc start="\${##\=" end="}" contains=@shDerefList 381 syn region shDeref matchgroup=PreProc start="\${##\=" end="}" contains=@shDerefList
382 syn region shDeref matchgroup=PreProc start="\${\$\$" end="}" contains=@shDerefList
366 endif 383 endif
367 384
368 " bash: ${!prefix*} and ${#parameter}: {{{1 385 " bash: ${!prefix*} and ${#parameter}: {{{1
369 " ==================================== 386 " ====================================
370 if exists("b:is_bash") 387 if exists("b:is_bash")
397 syn match shDerefOp contained "%\{1,2}" nextgroup=@shDerefPatternList 414 syn match shDerefOp contained "%\{1,2}" nextgroup=@shDerefPatternList
398 syn match shDerefPattern contained "[^{}]\+" contains=shDeref,shDerefSimple,shDerefPattern,shDerefString,shCommandSub,shDerefEscape nextgroup=shDerefPattern 415 syn match shDerefPattern contained "[^{}]\+" contains=shDeref,shDerefSimple,shDerefPattern,shDerefString,shCommandSub,shDerefEscape nextgroup=shDerefPattern
399 syn region shDerefPattern contained start="{" end="}" contains=shDeref,shDerefSimple,shDerefString,shCommandSub nextgroup=shDerefPattern 416 syn region shDerefPattern contained start="{" end="}" contains=shDeref,shDerefSimple,shDerefString,shCommandSub nextgroup=shDerefPattern
400 syn match shDerefEscape contained '\%(\\\\\)*\\.' 417 syn match shDerefEscape contained '\%(\\\\\)*\\.'
401 endif 418 endif
402 syn region shDerefString contained matchgroup=shOperator start=+'+ end=+'+ contains=shStringSpecial 419 syn region shDerefString contained matchgroup=shOperator start=+\%(\\\)\@<!'+ end=+'+ contains=shStringSpecial
403 syn region shDerefString contained matchgroup=shOperator start=+"+ skip=+\\"+ end=+"+ contains=@shDblQuoteList,shStringSpecial 420 syn region shDerefString contained matchgroup=shOperator start=+\%(\\\)\@<!"+ skip=+\\"+ end=+"+ contains=@shDblQuoteList,shStringSpecial
404 syn match shDerefString contained "\\["']" 421 syn match shDerefString contained "\\["']" nextgroup=shDerefPattern
405 422
406 if exists("b:is_bash") 423 if exists("b:is_bash")
407 " bash : ${parameter:offset} 424 " bash : ${parameter:offset}
408 " bash : ${parameter:offset:length} 425 " bash : ${parameter:offset:length}
409 syn region shDerefOp contained start=":[$[:alnum:]_]"me=e-1 end=":"me=e-1 end="}"me=e-1 contains=@shCommandSubList nextgroup=shDerefPOL 426 syn region shDerefOp contained start=":[$[:alnum:]_]"me=e-1 end=":"me=e-1 end="}"me=e-1 contains=@shCommandSubList nextgroup=shDerefPOL
414 syn match shDerefPPS contained '/\{1,2}' nextgroup=shDerefPPSleft 431 syn match shDerefPPS contained '/\{1,2}' nextgroup=shDerefPPSleft
415 syn region shDerefPPSleft contained start='.' skip=@\%(\\\)\/@ matchgroup=shDerefOp end='/' end='\ze}' nextgroup=shDerefPPSright contains=@shCommandSubList 432 syn region shDerefPPSleft contained start='.' skip=@\%(\\\)\/@ matchgroup=shDerefOp end='/' end='\ze}' nextgroup=shDerefPPSright contains=@shCommandSubList
416 syn region shDerefPPSright contained start='.' end='\ze}' contains=@shCommandSubList 433 syn region shDerefPPSright contained start='.' end='\ze}' contains=@shCommandSubList
417 endif 434 endif
418 435
436 " Arithmetic Parenthesized Expressions: {{{1
437 syn region shParen matchgroup=shArithRegion start='(\ze[^(]' end=')' contains=@shArithParenList
438
419 " Useful sh Keywords: {{{1 439 " Useful sh Keywords: {{{1
420 " =================== 440 " ===================
421 syn keyword shStatement break cd chdir continue eval exec exit kill newgrp pwd read readonly return shift test trap ulimit umask wait 441 syn keyword shStatement break cd chdir continue eval exec exit kill newgrp pwd read readonly return shift test trap ulimit umask wait
422 syn keyword shConditional contained elif else then 442 syn keyword shConditional contained elif else then
423 syn keyword shCondError elif else then 443 syn keyword shCondError elif else then
424 444
425 " Useful ksh Keywords: {{{1 445 " Useful ksh Keywords: {{{1
426 " ==================== 446 " ====================
427 if exists("b:is_kornshell") || exists("b:is_bash") 447 if exists("b:is_kornshell") || exists("b:is_bash")
428 syn keyword shStatement autoload bg false fc fg functions getopts hash history integer jobs let nohup print printf r stop suspend time times true type unalias whence 448 syn keyword shStatement autoload bg false fc fg functions getopts hash history integer jobs let nohup print printf r stop suspend times true type unalias whence
449 if exists("g:is_posix")
450 syn keyword shStatement command
451 else
452 syn keyword shStatement time
453 endif
429 454
430 " Useful bash Keywords: {{{1 455 " Useful bash Keywords: {{{1
431 " ===================== 456 " =====================
432 if exists("b:is_bash") 457 if exists("b:is_bash")
433 syn keyword shStatement bind builtin dirs disown enable help local logout popd pushd shopt source 458 syn keyword shStatement bind builtin dirs disown enable help local logout popd pushd shopt source
476 hi def link shDerefSpecial shDeref 501 hi def link shDerefSpecial shDeref
477 hi def link shDerefString shDoubleQuote 502 hi def link shDerefString shDoubleQuote
478 hi def link shDerefVar shDeref 503 hi def link shDerefVar shDeref
479 hi def link shDoubleQuote shString 504 hi def link shDoubleQuote shString
480 hi def link shEcho shString 505 hi def link shEcho shString
506 hi def link shEchoQuote shString
481 hi def link shEmbeddedEcho shString 507 hi def link shEmbeddedEcho shString
508 hi def link shEscape shCommandSub
482 hi def link shExSingleQuote shSingleQuote 509 hi def link shExSingleQuote shSingleQuote
483 hi def link shFunctionStart Delimiter 510 hi def link shFunction Function
484 hi def link shHereDoc shString 511 hi def link shHereDoc shString
485 hi def link shHerePayload shHereDoc 512 hi def link shHerePayload shHereDoc
486 hi def link shLoop shStatement 513 hi def link shLoop shStatement
487 hi def link shOption shCommandSub 514 hi def link shOption shCommandSub
488 hi def link shPattern shString 515 hi def link shPattern shString
516 hi def link shParen shArithmetic
489 hi def link shPosnParm shShellVariables 517 hi def link shPosnParm shShellVariables
518 hi def link shQuickComment shComment
490 hi def link shRange shOperator 519 hi def link shRange shOperator
491 hi def link shRedir shOperator 520 hi def link shRedir shOperator
521 hi def link shSetOption shOption
492 hi def link shSingleQuote shString 522 hi def link shSingleQuote shString
493 hi def link shSource shOperator 523 hi def link shSource shOperator
494 hi def link shStringSpecial shSpecial 524 hi def link shStringSpecial shSpecial
495 hi def link shSubShRegion shOperator 525 hi def link shSubShRegion shOperator
496 hi def link shTestOpr shConditional 526 hi def link shTestOpr shConditional