blob: 4370d6788f9fc692bbc4ea4244002c2a03e069c4 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim syntax file
2" Language: shell (sh) Korn shell (ksh) bash (sh)
3" Maintainer: Dr. Charles E. Campbell, Jr. <NdrOchipS@PcampbellAfamily.Mbiz>
4" Previous Maintainer: Lennart Schultz <Lennart.Schultz@ecmwf.int>
Bram Moolenaaradc21822011-04-01 18:03:16 +02005" Last Change: Feb 11, 2011
6" Version: 115
Bram Moolenaarcafda4f2005-09-06 19:25:11 +00007" URL: http://mysite.verizon.net/astronaut/vim/index.html#vimlinks_syntax
Bram Moolenaarc236c162008-07-13 17:41:49 +00008" For options and settings, please use: :help ft-sh-syntax
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +02009" This file includes many ideas from ?ric Brunet (eric.brunet@ens.fr)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010
Bram Moolenaard4755bb2004-09-02 19:12:26 +000011" For version 5.x: Clear all syntax items {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000012" For version 6.x: Quit when a syntax file was already loaded
13if version < 600
14 syntax clear
15elseif exists("b:current_syntax")
16 finish
17endif
18
Bram Moolenaard4755bb2004-09-02 19:12:26 +000019" handling /bin/sh with is_kornshell/is_sh {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000020" b:is_sh is set when "#! /bin/sh" is found;
21" However, it often is just a masquerade by bash (typically Linux)
22" or kornshell (typically workstations with Posix "sh").
23" So, when the user sets "is_bash" or "is_kornshell",
24" a b:is_sh is converted into b:is_bash/b:is_kornshell,
25" respectively.
26if !exists("b:is_kornshell") && !exists("b:is_bash")
Bram Moolenaar7fc904b2006-04-13 20:37:35 +000027 if exists("g:is_posix") && !exists("g:is_kornshell")
28 let g:is_kornshell= g:is_posix
29 endif
30 if exists("g:is_kornshell")
Bram Moolenaar071d4272004-06-13 20:20:40 +000031 let b:is_kornshell= 1
32 if exists("b:is_sh")
33 unlet b:is_sh
34 endif
Bram Moolenaar7fc904b2006-04-13 20:37:35 +000035 elseif exists("g:is_bash")
Bram Moolenaar071d4272004-06-13 20:20:40 +000036 let b:is_bash= 1
37 if exists("b:is_sh")
38 unlet b:is_sh
39 endif
40 else
41 let b:is_sh= 1
42 endif
43endif
44
Bram Moolenaarcd71fa32005-03-11 22:46:48 +000045" set up default g:sh_fold_enabled {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000046if !exists("g:sh_fold_enabled")
47 let g:sh_fold_enabled= 0
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000048elseif g:sh_fold_enabled != 0 && !has("folding")
49 let g:sh_fold_enabled= 0
Bram Moolenaarcd71fa32005-03-11 22:46:48 +000050 echomsg "Ignoring g:sh_fold_enabled=".g:sh_fold_enabled."; need to re-compile vim for +fold support"
51endif
Bram Moolenaarc236c162008-07-13 17:41:49 +000052if !exists("s:sh_fold_functions")
53 let s:sh_fold_functions = 1
54endif
55if !exists("s:sh_fold_heredoc")
56 let s:sh_fold_heredoc = 2
57endif
58if !exists("s:sh_fold_ifdofor")
59 let s:sh_fold_ifdofor = 4
60endif
Bram Moolenaarcd71fa32005-03-11 22:46:48 +000061if g:sh_fold_enabled && &fdm == "manual"
Bram Moolenaar00a927d2010-05-14 23:24:24 +020062 setlocal fdm=syntax
Bram Moolenaar071d4272004-06-13 20:20:40 +000063endif
64
Bram Moolenaarcd71fa32005-03-11 22:46:48 +000065" sh syntax is case sensitive {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000066syn case match
67
Bram Moolenaard4755bb2004-09-02 19:12:26 +000068" Clusters: contains=@... clusters {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000069"==================================
Bram Moolenaar5c736222010-01-06 20:54:52 +010070syn cluster shErrorList contains=shDoError,shIfError,shInError,shCaseError,shEsacError,shCurlyError,shParenError,shTestError,shOK
Bram Moolenaarc236c162008-07-13 17:41:49 +000071if exists("b:is_kornshell")
72 syn cluster ErrorList add=shDTestError
73endif
Bram Moolenaare90ee312010-08-05 22:08:47 +020074syn cluster shArithParenList contains=shArithmetic,shCaseEsac,shDeref,shDerefSimple,shEcho,shEscape,shNumber,shOperator,shPosnParm,shExSingleQuote,shExDoubleQuote,shRedir,shSingleQuote,shDoubleQuote,shStatement,shVariable,shAlias,shTest,shCtrlSeq,shSpecial,shParen,bashSpecialVariables,bashStatement
Bram Moolenaarc236c162008-07-13 17:41:49 +000075syn cluster shArithList contains=@shArithParenList,shParenError
Bram Moolenaar5c736222010-01-06 20:54:52 +010076syn cluster shCaseEsacList contains=shCaseStart,shCase,shCaseBar,shCaseIn,shComment,shDeref,shDerefSimple,shCaseCommandSub,shCaseExSingleQuote,shCaseSingleQuote,shCaseDoubleQuote,shCtrlSeq,@shErrorList,shStringSpecial,shCaseRange
Bram Moolenaar9964e462007-05-05 17:54:07 +000077syn cluster shCaseList contains=@shCommandSubList,shCaseEsac,shColon,shCommandSub,shCommandSub,shComment,shDo,shEcho,shExpr,shFor,shHereDoc,shIf,shRedir,shSetList,shSource,shStatement,shVariable,shCtrlSeq
Bram Moolenaar071d4272004-06-13 20:20:40 +000078syn cluster shColonList contains=@shCaseList
Bram Moolenaare90ee312010-08-05 22:08:47 +020079syn cluster shCommandSubList contains=shArithmetic,shDeref,shDerefSimple,shEscape,shNumber,shOperator,shPosnParm,shExSingleQuote,shSingleQuote,shExDoubleQuote,shDoubleQuote,shStatement,shVariable,shSubSh,shAlias,shTest,shCtrlSeq,shSpecial
Bram Moolenaar572cb562005-08-05 21:35:02 +000080syn cluster shCurlyList contains=shNumber,shComma,shDeref,shDerefSimple,shDerefSpecial
Bram Moolenaare90ee312010-08-05 22:08:47 +020081syn cluster shDblQuoteList contains=shCommandSub,shDeref,shDerefSimple,shPosnParm,shCtrlSeq,shSpecial
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000082syn cluster shDerefList contains=shDeref,shDerefSimple,shDerefVar,shDerefSpecial,shDerefWordError,shDerefPPS
Bram Moolenaar071d4272004-06-13 20:20:40 +000083syn cluster shDerefVarList contains=shDerefOp,shDerefVarArray,shDerefOpError
Bram Moolenaare90ee312010-08-05 22:08:47 +020084syn cluster shEchoList contains=shArithmetic,shCommandSub,shDeref,shDerefSimple,shExpr,shExSingleQuote,shExDoubleQuote,shSingleQuote,shDoubleQuote,shCtrlSeq,shEchoQuote
85syn cluster shExprList1 contains=shCharClass,shNumber,shOperator,shExSingleQuote,shExDoubleQuote,shSingleQuote,shDoubleQuote,shExpr,shDblBrace,shDeref,shDerefSimple,shCtrlSeq
Bram Moolenaar383f9bc2005-01-19 22:18:32 +000086syn cluster shExprList2 contains=@shExprList1,@shCaseList,shTest
Bram Moolenaar5c736222010-01-06 20:54:52 +010087syn cluster shFunctionList contains=@shCommandSubList,shCaseEsac,shColon,shCommandSub,shCommandSub,shComment,shDo,shEcho,shExpr,shFor,shHereDoc,shIf,shOption,shRedir,shSetList,shSource,shStatement,shVariable,shOperator,shCtrlSeq
Bram Moolenaar7263a772007-05-10 17:35:54 +000088if exists("b:is_kornshell") || exists("b:is_bash")
Bram Moolenaarc236c162008-07-13 17:41:49 +000089 syn cluster shFunctionList add=shRepeat
Bram Moolenaar7263a772007-05-10 17:35:54 +000090 syn cluster shFunctionList add=shDblBrace,shDblParen
91endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000092syn cluster shHereBeginList contains=@shCommandSubList
93syn cluster shHereList contains=shBeginHere,shHerePayload
94syn cluster shHereListDQ contains=shBeginHere,@shDblQuoteList,shHerePayload
Bram Moolenaare90ee312010-08-05 22:08:47 +020095syn cluster shIdList contains=shCommandSub,shWrapLineOperator,shSetOption,shDeref,shDerefSimple,shRedir,shExSingleQuote,shExDoubleQuote,shSingleQuote,shDoubleQuote,shExpr,shCtrlSeq,shStringSpecial
Bram Moolenaarc236c162008-07-13 17:41:49 +000096syn cluster shLoopList contains=@shCaseList,shTestOpr,shExpr,shDblBrace,shConditional,shCaseEsac,shTest,@shErrorList,shSet
Bram Moolenaar5c736222010-01-06 20:54:52 +010097syn cluster shSubShList contains=@shCommandSubList,shCaseEsac,shColon,shCommandSub,shCommandSub,shComment,shDo,shEcho,shExpr,shFor,shIf,shRedir,shSetList,shSource,shStatement,shVariable,shCtrlSeq,shOperator
Bram Moolenaare90ee312010-08-05 22:08:47 +020098syn cluster shTestList contains=shCharClass,shComment,shCommandSub,shDeref,shDerefSimple,shExDoubleQuote,shDoubleQuote,shExpr,shExpr,shNumber,shOperator,shExSingleQuote,shSingleQuote,shTestOpr,shTest,shCtrlSeq
Bram Moolenaar071d4272004-06-13 20:20:40 +000099
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000100" Echo: {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +0000101" ====
102" This one is needed INSIDE a CommandSub, so that `echo bla` be correct
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200103syn region shEcho matchgroup=shStatement start="\<echo\>" skip="\\$" matchgroup=shEchoDelim end="$" matchgroup=NONE end="[<>;&|()]"me=e-1 end="\d[<>]"me=e-2 end="\s#"me=e-2 contains=@shEchoList skipwhite nextgroup=shQuickComment
104syn region shEcho matchgroup=shStatement start="\<print\>" skip="\\$" matchgroup=shEchoDelim end="$" matchgroup=NONE end="[<>;&|()]"me=e-1 end="\d[<>]"me=e-2 end="\s#"me=e-2 contains=@shEchoList skipwhite nextgroup=shQuickComment
Bram Moolenaar5c736222010-01-06 20:54:52 +0100105syn match shEchoQuote contained '\%(\\\\\)*\\["`'()]'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000106
Bram Moolenaarc236c162008-07-13 17:41:49 +0000107" This must be after the strings, so that ... \" will be correct
Bram Moolenaare90ee312010-08-05 22:08:47 +0200108syn region shEmbeddedEcho contained matchgroup=shStatement start="\<print\>" skip="\\$" matchgroup=shEchoDelim end="$" matchgroup=NONE end="[<>;&|`)]"me=e-1 end="\d[<>]"me=e-2 end="\s#"me=e-2 contains=shNumber,shExSingleQuote,shSingleQuote,shDeref,shDerefSimple,shSpecialVar,shOperator,shExDoubleQuote,shDoubleQuote,shCharClass,shCtrlSeq
Bram Moolenaar071d4272004-06-13 20:20:40 +0000109
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000110" Alias: {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +0000111" =====
112if exists("b:is_kornshell") || exists("b:is_bash")
113 syn match shStatement "\<alias\>"
114 syn region shAlias matchgroup=shStatement start="\<alias\>\s\+\(\w\+\)\@=" skip="\\$" end="\>\|`"
115 syn region shAlias matchgroup=shStatement start="\<alias\>\s\+\(\w\+=\)\@=" skip="\\$" end="="
116endif
117
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000118" Error Codes: {{{1
119" ============
Bram Moolenaar071d4272004-06-13 20:20:40 +0000120syn match shDoError "\<done\>"
121syn match shIfError "\<fi\>"
122syn match shInError "\<in\>"
123syn match shCaseError ";;"
124syn match shEsacError "\<esac\>"
125syn match shCurlyError "}"
126syn match shParenError ")"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100127syn match shOK '\.\(done\|fi\|in\|esac\)'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000128if exists("b:is_kornshell")
129 syn match shDTestError "]]"
130endif
131syn match shTestError "]"
132
Bram Moolenaarc236c162008-07-13 17:41:49 +0000133" Options: {{{1
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000134" ====================
Bram Moolenaarfa01c392010-07-20 12:36:02 +0200135syn match shOption "\s\zs[-+][-_a-zA-Z0-9]\+\>"
Bram Moolenaarc236c162008-07-13 17:41:49 +0000136syn match shOption "\s\zs--[^ \t$`'"|]\+"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000137
Bram Moolenaar7263a772007-05-10 17:35:54 +0000138" File Redirection Highlighted As Operators: {{{1
139"===========================================
140syn match shRedir "\d\=>\(&[-0-9]\)\="
141syn match shRedir "\d\=>>-\="
142syn match shRedir "\d\=<\(&[-0-9]\)\="
143syn match shRedir "\d<<-\="
144
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000145" Operators: {{{1
146" ==========
Bram Moolenaar7263a772007-05-10 17:35:54 +0000147syn match shOperator "<<\|>>" contained
Bram Moolenaarc236c162008-07-13 17:41:49 +0000148syn match shOperator "[!&;|]" contained
149syn match shOperator "\[[[^:]\|\]]" contained
Bram Moolenaar071d4272004-06-13 20:20:40 +0000150syn match shOperator "!\==" skipwhite nextgroup=shPattern
Bram Moolenaare90ee312010-08-05 22:08:47 +0200151syn match shPattern "\<\S\+\())\)\@=" contained contains=shExSingleQuote,shSingleQuote,shExDoubleQuote,shDoubleQuote,shDeref
Bram Moolenaar071d4272004-06-13 20:20:40 +0000152
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000153" Subshells: {{{1
154" ==========
Bram Moolenaar5c736222010-01-06 20:54:52 +0100155syn region shExpr transparent matchgroup=shExprRegion start="{" end="}" contains=@shExprList2 nextgroup=shMoreSpecial
156syn region shSubSh transparent matchgroup=shSubShRegion start="(" end=")" contains=@shSubShList nextgroup=shMoreSpecial
Bram Moolenaar071d4272004-06-13 20:20:40 +0000157
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000158" Tests: {{{1
159"=======
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200160syn region shExpr matchgroup=shRange start="\[" skip=+\\\\\|\\$\|\[+ end="\]" contains=@shTestList,shSpecial
Bram Moolenaar5c736222010-01-06 20:54:52 +0100161syn region shTest transparent matchgroup=shStatement start="\<test\s" skip=+\\\\\|\\$+ matchgroup=NONE end="[;&|]"me=e-1 end="$" contains=@shExprList1
Bram Moolenaar9964e462007-05-05 17:54:07 +0000162syn match shTestOpr contained "<=\|>=\|!=\|==\|-.\>\|-\(nt\|ot\|ef\|eq\|ne\|lt\|le\|gt\|ge\)\>\|[!<>]"
163syn match shTestOpr contained '=' skipwhite nextgroup=shTestDoubleQuote,shTestSingleQuote,shTestPattern
164syn match shTestPattern contained '\w\+'
165syn match shTestDoubleQuote contained '"[^"]*"'
166syn match shTestSingleQuote contained '\\.'
167syn match shTestSingleQuote contained "'[^']*'"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000168if exists("b:is_kornshell") || exists("b:is_bash")
169 syn region shDblBrace matchgroup=Delimiter start="\[\[" skip=+\\\\\|\\$+ end="\]\]" contains=@shTestList
170 syn region shDblParen matchgroup=Delimiter start="((" skip=+\\\\\|\\$+ end="))" contains=@shTestList
171endif
172
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000173" Character Class In Range: {{{1
174" =========================
Bram Moolenaar071d4272004-06-13 20:20:40 +0000175syn match shCharClass contained "\[:\(backspace\|escape\|return\|xdigit\|alnum\|alpha\|blank\|cntrl\|digit\|graph\|lower\|print\|punct\|space\|upper\|tab\):\]"
176
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000177" Loops: do, if, while, until {{{1
178" ======
Bram Moolenaarc236c162008-07-13 17:41:49 +0000179if (g:sh_fold_enabled % (s:sh_fold_ifdofor * 2))/s:sh_fold_ifdofor
Bram Moolenaar8dff8182006-04-06 20:18:50 +0000180 syn region shDo fold transparent matchgroup=shConditional start="\<do\>" matchgroup=shConditional end="\<done\>" contains=@shLoopList
Bram Moolenaarc236c162008-07-13 17:41:49 +0000181 syn region shIf fold transparent matchgroup=shConditional start="\<if\_s" matchgroup=shConditional end="\<;\_s*then\>" end="\<fi\>" contains=@shLoopList,shDblBrace,shDblParen,shFunctionKey
182 syn region shFor fold matchgroup=shLoop start="\<for\_s" end="\<in\_s" end="\<do\>"me=e-2 contains=@shLoopList,shDblParen skipwhite nextgroup=shCurlyIn
Bram Moolenaar8dff8182006-04-06 20:18:50 +0000183else
184 syn region shDo transparent matchgroup=shConditional start="\<do\>" matchgroup=shConditional end="\<done\>" contains=@shLoopList
Bram Moolenaarc236c162008-07-13 17:41:49 +0000185 syn region shIf transparent matchgroup=shConditional start="\<if\_s" matchgroup=shConditional end="\<;\_s*then\>" end="\<fi\>" contains=@shLoopList,shDblBrace,shDblParen,shFunctionKey
186 syn region shFor matchgroup=shLoop start="\<for\_s" end="\<in\>" end="\<do\>"me=e-2 contains=@shLoopList,shDblParen skipwhite nextgroup=shCurlyIn
Bram Moolenaar8dff8182006-04-06 20:18:50 +0000187endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000188if exists("b:is_kornshell") || exists("b:is_bash")
Bram Moolenaarc236c162008-07-13 17:41:49 +0000189 syn cluster shCaseList add=shRepeat
190 syn cluster shFunctionList add=shRepeat
191 syn region shRepeat matchgroup=shLoop start="\<while\_s" end="\<in\_s" end="\<do\>"me=e-2 contains=@shLoopList,shDblParen,shDblBrace
192 syn region shRepeat matchgroup=shLoop start="\<until\_s" end="\<in\_s" end="\<do\>"me=e-2 contains=@shLoopList,shDblParen,shDblBrace
193 syn region shCaseEsac matchgroup=shConditional start="\<select\s" matchgroup=shConditional end="\<in\>" end="\<do\>" contains=@shLoopList
Bram Moolenaar071d4272004-06-13 20:20:40 +0000194else
Bram Moolenaarc236c162008-07-13 17:41:49 +0000195 syn region shRepeat matchgroup=shLoop start="\<while\_s" end="\<do\>"me=e-2 contains=@shLoopList
196 syn region shRepeat matchgroup=shLoop start="\<until\_s" end="\<do\>"me=e-2 contains=@shLoopList
Bram Moolenaar071d4272004-06-13 20:20:40 +0000197endif
Bram Moolenaar572cb562005-08-05 21:35:02 +0000198syn region shCurlyIn contained matchgroup=Delimiter start="{" end="}" contains=@shCurlyList
199syn match shComma contained ","
Bram Moolenaar071d4272004-06-13 20:20:40 +0000200
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000201" Case: case...esac {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +0000202" ====
Bram Moolenaarc236c162008-07-13 17:41:49 +0000203syn match shCaseBar contained skipwhite "\(^\|[^\\]\)\(\\\\\)*\zs|" nextgroup=shCase,shCaseStart,shCaseBar,shComment,shCaseExSingleQuote,shCaseSingleQuote,shCaseDoubleQuote
Bram Moolenaar071d4272004-06-13 20:20:40 +0000204syn match shCaseStart contained skipwhite skipnl "(" nextgroup=shCase,shCaseBar
Bram Moolenaarc236c162008-07-13 17:41:49 +0000205if (g:sh_fold_enabled % (s:sh_fold_ifdofor * 2))/s:sh_fold_ifdofor
Bram Moolenaar5c736222010-01-06 20:54:52 +0100206 syn region shCase fold contained skipwhite skipnl matchgroup=shSnglCase start="\%(\\.\|[^#$()'" \t]\)\{-}\zs)" end=";;" end="esac"me=s-1 contains=@shCaseList nextgroup=shCaseStart,shCase,shComment
Bram Moolenaar8dff8182006-04-06 20:18:50 +0000207 syn region shCaseEsac fold matchgroup=shConditional start="\<case\>" end="\<esac\>" contains=@shCaseEsacList
208else
Bram Moolenaar5c736222010-01-06 20:54:52 +0100209 syn region shCase contained skipwhite skipnl matchgroup=shSnglCase start="\%(\\.\|[^#$()'" \t]\)\{-}\zs)" end=";;" end="esac"me=s-1 contains=@shCaseList nextgroup=shCaseStart,shCase,shComment
Bram Moolenaar8dff8182006-04-06 20:18:50 +0000210 syn region shCaseEsac matchgroup=shConditional start="\<case\>" end="\<esac\>" contains=@shCaseEsacList
211endif
Bram Moolenaardf177f62005-02-22 08:39:57 +0000212syn keyword shCaseIn contained skipwhite skipnl in nextgroup=shCase,shCaseStart,shCaseBar,shComment,shCaseExSingleQuote,shCaseSingleQuote,shCaseDoubleQuote
213if exists("b:is_bash")
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200214 syn region shCaseExSingleQuote matchgroup=shQuote start=+\$'+ skip=+\\\\\|\\.+ end=+'+ contains=shStringSpecial,shSpecial skipwhite skipnl nextgroup=shCaseBar contained
Bram Moolenaardf177f62005-02-22 08:39:57 +0000215else
216 syn region shCaseExSingleQuote matchgroup=Error start=+\$'+ skip=+\\\\\|\\.+ end=+'+ contains=shStringSpecial skipwhite skipnl nextgroup=shCaseBar contained
217endif
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200218syn region shCaseSingleQuote matchgroup=shQuote start=+'+ end=+'+ contains=shStringSpecial skipwhite skipnl nextgroup=shCaseBar contained
219syn region shCaseDoubleQuote matchgroup=shQuote start=+"+ skip=+\\\\\|\\.+ end=+"+ contains=@shDblQuoteList,shStringSpecial skipwhite skipnl nextgroup=shCaseBar contained
Bram Moolenaar071d4272004-06-13 20:20:40 +0000220syn region shCaseCommandSub start=+`+ skip=+\\\\\|\\.+ end=+`+ contains=@shCommandSubList skipwhite skipnl nextgroup=shCaseBar contained
Bram Moolenaar5c736222010-01-06 20:54:52 +0100221syn region shCaseRange matchgroup=Delimiter start=+\[+ skip=+\\\\+ end=+]+ contained
Bram Moolenaar071d4272004-06-13 20:20:40 +0000222
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000223" Misc: {{{1
224"======
Bram Moolenaar071d4272004-06-13 20:20:40 +0000225syn match shWrapLineOperator "\\$"
226syn region shCommandSub start="`" skip="\\\\\|\\." end="`" contains=@shCommandSubList
Bram Moolenaarc236c162008-07-13 17:41:49 +0000227syn match shEscape contained '\\.'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000228
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000229" $() and $(()): {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +0000230" $(..) is not supported by sh (Bourne shell). However, apparently
231" some systems (HP?) have as their /bin/sh a (link to) Korn shell
232" (ie. Posix compliant shell). /bin/ksh should work for those
233" systems too, however, so the following syntax will flag $(..) as
234" an Error under /bin/sh. By consensus of vimdev'ers!
235if exists("b:is_kornshell") || exists("b:is_bash")
236 syn region shCommandSub matchgroup=shCmdSubRegion start="\$(" skip='\\\\\|\\.' end=")" contains=@shCommandSubList
Bram Moolenaarc236c162008-07-13 17:41:49 +0000237 syn region shArithmetic matchgroup=shArithRegion start="\$((" skip='\\\\\|\\.' end="))" contains=@shArithList
Bram Moolenaar071d4272004-06-13 20:20:40 +0000238 syn match shSkipInitWS contained "^\s\+"
239else
Bram Moolenaardf177f62005-02-22 08:39:57 +0000240 syn region shCommandSub matchgroup=Error start="\$(" end=")" contains=@shCommandSubList
Bram Moolenaar071d4272004-06-13 20:20:40 +0000241endif
242
243if exists("b:is_bash")
244 syn cluster shCommandSubList add=bashSpecialVariables,bashStatement
245 syn cluster shCaseList add=bashAdminStatement,bashStatement
246 syn keyword bashSpecialVariables contained BASH BASH_ENV BASH_VERSINFO BASH_VERSION CDPATH DIRSTACK EUID FCEDIT FIGNORE GLOBIGNORE GROUPS HISTCMD HISTCONTROL HISTFILE HISTFILESIZE HISTIGNORE HISTSIZE HOME HOSTFILE HOSTNAME HOSTTYPE IFS IGNOREEOF INPUTRC LANG LC_ALL LC_COLLATE LC_MESSAGES LINENO MACHTYPE MAIL MAILCHECK MAILPATH OLDPWD OPTARG OPTERR OPTIND OSTYPE PATH PIPESTATUS PPID PROMPT_COMMAND PS1 PS2 PS3 PS4 PWD RANDOM REPLY SECONDS SHELLOPTS SHLVL TIMEFORMAT TIMEOUT UID auto_resume histchars
247 syn keyword bashStatement chmod clear complete du egrep expr fgrep find gnufind gnugrep grep install less ls mkdir mv rm rmdir rpm sed sleep sort strip tail touch
248 syn keyword bashAdminStatement daemon killall killproc nice reload restart start status stop
249endif
250
251if exists("b:is_kornshell")
252 syn cluster shCommandSubList add=kshSpecialVariables,kshStatement
253 syn cluster shCaseList add=kshStatement
254 syn keyword kshSpecialVariables contained CDPATH COLUMNS EDITOR ENV ERRNO FCEDIT FPATH HISTFILE HISTSIZE HOME IFS LINENO LINES MAIL MAILCHECK MAILPATH OLDPWD OPTARG OPTIND PATH PPID PS1 PS2 PS3 PS4 PWD RANDOM REPLY SECONDS SHELL TMOUT VISUAL
255 syn keyword kshStatement cat chmod clear cp du egrep expr fgrep find grep install killall less ls mkdir mv nice printenv rm rmdir sed sort strip stty tail touch tput
256endif
257
258syn match shSource "^\.\s"
259syn match shSource "\s\.\s"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100260"syn region shColon start="^\s*:" end="$" end="\s#"me=e-2 contains=@shColonList
261syn region shColon start="^\s*\zs:" end="$" end="\s#"me=e-2
Bram Moolenaar071d4272004-06-13 20:20:40 +0000262
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000263" String And Character Constants: {{{1
264"================================
Bram Moolenaar9964e462007-05-05 17:54:07 +0000265syn match shNumber "-\=\<\d\+\>#\="
266syn match shCtrlSeq "\\\d\d\d\|\\[abcfnrtv0]" contained
Bram Moolenaardf177f62005-02-22 08:39:57 +0000267if exists("b:is_bash")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100268 syn match shSpecial "\\\o\o\o\|\\x\x\x\|\\c[^"]\|\\[abefnrtv]" contained
Bram Moolenaardf177f62005-02-22 08:39:57 +0000269endif
270if exists("b:is_bash")
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200271 syn region shExSingleQuote matchgroup=shQuote start=+\$'+ skip=+\\\\\|\\.+ end=+'+ contains=shStringSpecial,shSpecial
Bram Moolenaare90ee312010-08-05 22:08:47 +0200272 syn region shExDoubleQuote matchgroup=shQuote start=+\$"+ skip=+\\\\\|\\.\|\\"+ end=+"+ contains=@shDblQuoteList,shStringSpecial,shSpecial
Bram Moolenaardf177f62005-02-22 08:39:57 +0000273else
Bram Moolenaar9964e462007-05-05 17:54:07 +0000274 syn region shExSingleQuote matchGroup=Error start=+\$'+ skip=+\\\\\|\\.+ end=+'+ contains=shStringSpecial
Bram Moolenaare90ee312010-08-05 22:08:47 +0200275 syn region shExDoubleQuote matchGroup=Error start=+\$"+ skip=+\\\\\|\\.+ end=+"+ contains=shStringSpecial
Bram Moolenaardf177f62005-02-22 08:39:57 +0000276endif
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200277syn region shSingleQuote matchgroup=shQuote start=+'+ end=+'+ contains=@Spell
278syn region shDoubleQuote matchgroup=shQuote start=+"+ skip=+\\"+ end=+"+ contains=@shDblQuoteList,shStringSpecial,@Spell
Bram Moolenaare37d50a2008-08-06 17:06:04 +0000279syn match shStringSpecial "[^[:print:] \t]" contained
Bram Moolenaar7263a772007-05-10 17:35:54 +0000280syn match shStringSpecial "\%(\\\\\)*\\[\\"'`$()#]"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100281syn match shSpecial "[^\\]\zs\%(\\\\\)*\\[\\"'`$()#]" nextgroup=shMoreSpecial
Bram Moolenaar7263a772007-05-10 17:35:54 +0000282syn match shSpecial "^\%(\\\\\)*\\[\\"'`$()#]"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100283syn match shMoreSpecial "\%(\\\\\)*\\[\\"'`$()#]" nextgroup=shMoreSpecial contained
Bram Moolenaar071d4272004-06-13 20:20:40 +0000284
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000285" Comments: {{{1
286"==========
Bram Moolenaar5c736222010-01-06 20:54:52 +0100287syn cluster shCommentGroup contains=shTodo,@Spell
288syn keyword shTodo contained COMBAK FIXME TODO XXX
289syn match shComment "^\s*\zs#.*$" contains=@shCommentGroup
290syn match shComment "\s\zs#.*$" contains=@shCommentGroup
291syn match shQuickComment contained "#.*$"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000292
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000293" Here Documents: {{{1
294" =========================================
Bram Moolenaar071d4272004-06-13 20:20:40 +0000295if version < 600
296 syn region shHereDoc matchgroup=shRedir start="<<\s*\**END[a-zA-Z_0-9]*\**" matchgroup=shRedir end="^END[a-zA-Z_0-9]*$" contains=@shDblQuoteList
297 syn region shHereDoc matchgroup=shRedir start="<<-\s*\**END[a-zA-Z_0-9]*\**" matchgroup=shRedir end="^\s*END[a-zA-Z_0-9]*$" contains=@shDblQuoteList
298 syn region shHereDoc matchgroup=shRedir start="<<\s*\**EOF\**" matchgroup=shRedir end="^EOF$" contains=@shDblQuoteList
299 syn region shHereDoc matchgroup=shRedir start="<<-\s*\**EOF\**" matchgroup=shRedir end="^\s*EOF$" contains=@shDblQuoteList
300 syn region shHereDoc matchgroup=shRedir start="<<\s*\**\.\**" matchgroup=shRedir end="^\.$" contains=@shDblQuoteList
301 syn region shHereDoc matchgroup=shRedir start="<<-\s*\**\.\**" matchgroup=shRedir end="^\s*\.$" contains=@shDblQuoteList
302
Bram Moolenaarc236c162008-07-13 17:41:49 +0000303elseif (g:sh_fold_enabled % (s:sh_fold_heredoc * 2))/s:sh_fold_heredoc
Bram Moolenaar9964e462007-05-05 17:54:07 +0000304 syn region shHereDoc matchgroup=shRedir fold start="<<\s*\z(\S*\)" matchgroup=shRedir end="^\z1\s*$" contains=@shDblQuoteList
Bram Moolenaarcd71fa32005-03-11 22:46:48 +0000305 syn region shHereDoc matchgroup=shRedir fold start="<<\s*\"\z(\S*\)\"" matchgroup=shRedir end="^\z1\s*$"
306 syn region shHereDoc matchgroup=shRedir fold start="<<\s*'\z(\S*\)'" matchgroup=shRedir end="^\z1\s*$"
307 syn region shHereDoc matchgroup=shRedir fold start="<<-\s*\z(\S*\)" matchgroup=shRedir end="^\s*\z1\s*$" contains=@shDblQuoteList
308 syn region shHereDoc matchgroup=shRedir fold start="<<-\s*\"\z(\S*\)\"" matchgroup=shRedir end="^\s*\z1\s*$"
309 syn region shHereDoc matchgroup=shRedir fold start="<<-\s*'\z(\S*\)'" matchgroup=shRedir end="^\s*\z1\s*$"
310 syn region shHereDoc matchgroup=shRedir fold start="<<\s*\\\_$\_s*\z(\S*\)" matchgroup=shRedir end="^\z1\s*$"
311 syn region shHereDoc matchgroup=shRedir fold start="<<\s*\\\_$\_s*\"\z(\S*\)\"" matchgroup=shRedir end="^\z1\s*$"
312 syn region shHereDoc matchgroup=shRedir fold start="<<-\s*\\\_$\_s*'\z(\S*\)'" matchgroup=shRedir end="^\s*\z1\s*$"
313 syn region shHereDoc matchgroup=shRedir fold start="<<-\s*\\\_$\_s*\z(\S*\)" matchgroup=shRedir end="^\s*\z1\s*$"
314 syn region shHereDoc matchgroup=shRedir fold start="<<-\s*\\\_$\_s*\"\z(\S*\)\"" matchgroup=shRedir end="^\s*\z1\s*$"
315 syn region shHereDoc matchgroup=shRedir fold start="<<\s*\\\_$\_s*'\z(\S*\)'" matchgroup=shRedir end="^\z1\s*$"
Bram Moolenaar9964e462007-05-05 17:54:07 +0000316 syn region shHereDoc matchgroup=shRedir fold start="<<\\\z(\S*\)" matchgroup=shRedir end="^\z1\s*$"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000317
Bram Moolenaar071d4272004-06-13 20:20:40 +0000318else
Bram Moolenaarcd71fa32005-03-11 22:46:48 +0000319 syn region shHereDoc matchgroup=shRedir start="<<\s*\\\=\z(\S*\)" matchgroup=shRedir end="^\z1\s*$" contains=@shDblQuoteList
320 syn region shHereDoc matchgroup=shRedir start="<<\s*\"\z(\S*\)\"" matchgroup=shRedir end="^\z1\s*$"
321 syn region shHereDoc matchgroup=shRedir start="<<-\s*\z(\S*\)" matchgroup=shRedir end="^\s*\z1\s*$" contains=@shDblQuoteList
322 syn region shHereDoc matchgroup=shRedir start="<<-\s*'\z(\S*\)'" matchgroup=shRedir end="^\s*\z1\s*$"
323 syn region shHereDoc matchgroup=shRedir start="<<\s*'\z(\S*\)'" matchgroup=shRedir end="^\z1\s*$"
324 syn region shHereDoc matchgroup=shRedir start="<<-\s*\"\z(\S*\)\"" matchgroup=shRedir end="^\s*\z1\s*$"
325 syn region shHereDoc matchgroup=shRedir start="<<\s*\\\_$\_s*\z(\S*\)" matchgroup=shRedir end="^\z1\s*$"
326 syn region shHereDoc matchgroup=shRedir start="<<-\s*\\\_$\_s*\z(\S*\)" matchgroup=shRedir end="^\s*\z1\s*$"
327 syn region shHereDoc matchgroup=shRedir start="<<-\s*\\\_$\_s*'\z(\S*\)'" matchgroup=shRedir end="^\s*\z1\s*$"
328 syn region shHereDoc matchgroup=shRedir start="<<\s*\\\_$\_s*'\z(\S*\)'" matchgroup=shRedir end="^\z1\s*$"
329 syn region shHereDoc matchgroup=shRedir start="<<\s*\\\_$\_s*\"\z(\S*\)\"" matchgroup=shRedir end="^\z1\s*$"
330 syn region shHereDoc matchgroup=shRedir start="<<-\s*\\\_$\_s*\"\z(\S*\)\"" matchgroup=shRedir end="^\s*\z1\s*$"
Bram Moolenaar9964e462007-05-05 17:54:07 +0000331 syn region shHereDoc matchgroup=shRedir start="<<\\\z(\S*\)" matchgroup=shRedir end="^\z1\s*$"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000332endif
333
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000334" Here Strings: {{{1
335" =============
336if exists("b:is_bash")
337 syn match shRedir "<<<"
338endif
339
340" Identifiers: {{{1
341"=============
Bram Moolenaarc236c162008-07-13 17:41:49 +0000342syn match shSetOption "\s\zs[-+][a-zA-Z0-9]\+\>" contained
343syn match shVariable "\<\([bwglsav]:\)\=[a-zA-Z0-9.!@_%+,]*\ze=" nextgroup=shSetIdentifier
Bram Moolenaare90ee312010-08-05 22:08:47 +0200344syn match shSetIdentifier "=" contained nextgroup=shPattern,shDeref,shDerefSimple,shDoubleQuote,shExDoubleQuote,shSingleQuote,shExSingleQuote
Bram Moolenaar071d4272004-06-13 20:20:40 +0000345if exists("b:is_bash")
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200346 syn region shSetList oneline matchgroup=shSet start="\<\(declare\|typeset\|local\|export\|unset\)\>\ze[^/]" end="$" matchgroup=shSetListDelim end="\ze[}|);&]" matchgroup=NONE end="\ze\s\+#\|=" contains=@shIdList
347 syn region shSetList oneline matchgroup=shSet start="\<set\>\ze[^/]" end="\ze[;|)]\|$" matchgroup=shSetListDelim end="\ze[}|);&]" matchgroup=NONE end="\ze\s\+[#=]" contains=@shIdList
Bram Moolenaar071d4272004-06-13 20:20:40 +0000348elseif exists("b:is_kornshell")
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200349 syn region shSetList oneline matchgroup=shSet start="\<\(typeset\|export\|unset\)\>\ze[^/]" end="$" matchgroup=shSetListDelim end="\ze[}|);&]" matchgroup=NONE end="\ze\s\+[#=]" contains=@shIdList
350 syn region shSetList oneline matchgroup=shSet start="\<set\>\ze[^/]" end="$" matchgroup=shSetListDelim end="\ze[}|);&]" matchgroup=NONE end="\ze\s\+[#=]" contains=@shIdList
Bram Moolenaar071d4272004-06-13 20:20:40 +0000351else
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200352 syn region shSetList oneline matchgroup=shSet start="\<\(set\|export\|unset\)\>\ze[^/]" end="$" matchgroup=shSetListDelim end="\ze[}|);&]" matchgroup=NONE end="\ze\s\+[#=]" contains=@shIdList
Bram Moolenaar071d4272004-06-13 20:20:40 +0000353endif
354
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000355" Functions: {{{1
Bram Moolenaarc236c162008-07-13 17:41:49 +0000356if !exists("g:is_posix")
357 syn keyword shFunctionKey function skipwhite skipnl nextgroup=shFunctionTwo
358endif
359
360if exists("b:is_bash")
361 if (g:sh_fold_enabled % (s:sh_fold_functions * 2))/s:sh_fold_functions
362 syn region shFunctionOne fold matchgroup=shFunction start="^\s*\h[-a-zA-Z_0-9]*\s*()\_s*{" end="}" contains=@shFunctionList skipwhite skipnl nextgroup=shFunctionStart,shQuickComment
363 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
364 else
365 syn region shFunctionOne matchgroup=shFunction start="^\s*\h[-a-zA-Z_0-9]*\s*()\_s*{" end="}" contains=@shFunctionList
366 syn region shFunctionTwo matchgroup=shFunction start="\h[-a-zA-Z_0-9]*\s*\%(()\)\=\_s*{" end="}" contains=shFunctionKey,@shFunctionList contained
367 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000368else
Bram Moolenaarc236c162008-07-13 17:41:49 +0000369 if (g:sh_fold_enabled % (s:sh_fold_functions * 2))/s:sh_fold_functions
370 syn region shFunctionOne fold matchgroup=shFunction start="^\s*\h\w*\s*()\_s*{" end="}" contains=@shFunctionList skipwhite skipnl nextgroup=shFunctionStart,shQuickComment
371 syn region shFunctionTwo fold matchgroup=shFunction start="\h\w*\s*\%(()\)\=\_s*{" end="}" contains=shFunctionKey,@shFunctionList contained skipwhite skipnl nextgroup=shFunctionStart,shQuickComment
372 else
373 syn region shFunctionOne matchgroup=shFunction start="^\s*\h\w*\s*()\_s*{" end="}" contains=@shFunctionList
374 syn region shFunctionTwo matchgroup=shFunction start="\h\w*\s*\%(()\)\=\_s*{" end="}" contains=shFunctionKey,@shFunctionList contained
375 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000376endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000377
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000378" Parameter Dereferencing: {{{1
379" ========================
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000380syn match shDerefSimple "\$\%(\h\w*\|\d\)"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000381syn region shDeref matchgroup=PreProc start="\${" end="}" contains=@shDerefList,shDerefVarArray
382syn match shDerefWordError "[^}$[]" contained
383syn match shDerefSimple "\$[-#*@!?]"
384syn match shDerefSimple "\$\$"
385if exists("b:is_bash") || exists("b:is_kornshell")
386 syn region shDeref matchgroup=PreProc start="\${##\=" end="}" contains=@shDerefList
Bram Moolenaarc236c162008-07-13 17:41:49 +0000387 syn region shDeref matchgroup=PreProc start="\${\$\$" end="}" contains=@shDerefList
Bram Moolenaar071d4272004-06-13 20:20:40 +0000388endif
389
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000390" bash: ${!prefix*} and ${#parameter}: {{{1
391" ====================================
Bram Moolenaar071d4272004-06-13 20:20:40 +0000392if exists("b:is_bash")
393 syn region shDeref matchgroup=PreProc start="\${!" end="\*\=}" contains=@shDerefList,shDerefOp
394 syn match shDerefVar contained "{\@<=!\w\+" nextgroup=@shDerefVarList
395endif
396
397syn match shDerefSpecial contained "{\@<=[-*@?0]" nextgroup=shDerefOp,shDerefOpError
398syn match shDerefSpecial contained "\({[#!]\)\@<=[[:alnum:]*@_]\+" nextgroup=@shDerefVarList,shDerefOp
399syn match shDerefVar contained "{\@<=\w\+" nextgroup=@shDerefVarList
400
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000401" sh ksh bash : ${var[... ]...} array reference: {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +0000402syn region shDerefVarArray contained matchgroup=shDeref start="\[" end="]" contains=@shCommandSubList nextgroup=shDerefOp,shDerefOpError
403
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000404" Special ${parameter OPERATOR word} handling: {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +0000405" sh ksh bash : ${parameter:-word} word is default value
406" sh ksh bash : ${parameter:=word} assign word as default value
407" sh ksh bash : ${parameter:?word} display word if parameter is null
408" sh ksh bash : ${parameter:+word} use word if parameter is not null, otherwise nothing
409" ksh bash : ${parameter#pattern} remove small left pattern
410" ksh bash : ${parameter##pattern} remove large left pattern
411" ksh bash : ${parameter%pattern} remove small right pattern
412" ksh bash : ${parameter%%pattern} remove large right pattern
Bram Moolenaaradc21822011-04-01 18:03:16 +0200413" ksh bash : ${parameter^pattern} Case modification
414" ksh bash : ${parameter^^pattern} Case modification
415" ksh bash : ${parameter,pattern} Case modification
416" ksh bash : ${parameter,,pattern} Case modification
Bram Moolenaar071d4272004-06-13 20:20:40 +0000417syn cluster shDerefPatternList contains=shDerefPattern,shDerefString
418syn match shDerefOpError contained ":[[:punct:]]"
419syn match shDerefOp contained ":\=[-=?]" nextgroup=@shDerefPatternList
420syn match shDerefOp contained ":\=+" nextgroup=@shDerefPatternList
421if exists("b:is_bash") || exists("b:is_kornshell")
422 syn match shDerefOp contained "#\{1,2}" nextgroup=@shDerefPatternList
423 syn match shDerefOp contained "%\{1,2}" nextgroup=@shDerefPatternList
Bram Moolenaaradc21822011-04-01 18:03:16 +0200424 syn match shDerefOp contained "\^\{1,2}" nextgroup=@shDerefPatternList
425 syn match shDerefOp contained ",\{1,2}" nextgroup=@shDerefPatternList
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000426 syn match shDerefPattern contained "[^{}]\+" contains=shDeref,shDerefSimple,shDerefPattern,shDerefString,shCommandSub,shDerefEscape nextgroup=shDerefPattern
Bram Moolenaar071d4272004-06-13 20:20:40 +0000427 syn region shDerefPattern contained start="{" end="}" contains=shDeref,shDerefSimple,shDerefString,shCommandSub nextgroup=shDerefPattern
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000428 syn match shDerefEscape contained '\%(\\\\\)*\\.'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000429endif
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200430syn region shDerefString contained matchgroup=shDerefDelim start=+\%(\\\)\@<!'+ end=+'+ contains=shStringSpecial
431syn region shDerefString contained matchgroup=shDerefDelim start=+\%(\\\)\@<!"+ skip=+\\"+ end=+"+ contains=@shDblQuoteList,shStringSpecial
Bram Moolenaarc236c162008-07-13 17:41:49 +0000432syn match shDerefString contained "\\["']" nextgroup=shDerefPattern
Bram Moolenaar071d4272004-06-13 20:20:40 +0000433
Bram Moolenaar071d4272004-06-13 20:20:40 +0000434if exists("b:is_bash")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000435 " bash : ${parameter:offset}
436 " bash : ${parameter:offset:length}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000437 syn region shDerefOp contained start=":[$[:alnum:]_]"me=e-1 end=":"me=e-1 end="}"me=e-1 contains=@shCommandSubList nextgroup=shDerefPOL
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000438 syn match shDerefPOL contained ":[^}]\+" contains=@shCommandSubList
439
440 " bash : ${parameter//pattern/string}
441 " bash : ${parameter//pattern}
442 syn match shDerefPPS contained '/\{1,2}' nextgroup=shDerefPPSleft
Bram Moolenaara5792f52005-11-23 21:25:05 +0000443 syn region shDerefPPSleft contained start='.' skip=@\%(\\\)\/@ matchgroup=shDerefOp end='/' end='\ze}' nextgroup=shDerefPPSright contains=@shCommandSubList
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000444 syn region shDerefPPSright contained start='.' end='\ze}' contains=@shCommandSubList
Bram Moolenaar071d4272004-06-13 20:20:40 +0000445endif
446
Bram Moolenaarc236c162008-07-13 17:41:49 +0000447" Arithmetic Parenthesized Expressions: {{{1
448syn region shParen matchgroup=shArithRegion start='(\ze[^(]' end=')' contains=@shArithParenList
449
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000450" Useful sh Keywords: {{{1
451" ===================
Bram Moolenaar071d4272004-06-13 20:20:40 +0000452syn keyword shStatement break cd chdir continue eval exec exit kill newgrp pwd read readonly return shift test trap ulimit umask wait
453syn keyword shConditional contained elif else then
454syn keyword shCondError elif else then
455
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000456" Useful ksh Keywords: {{{1
457" ====================
Bram Moolenaar071d4272004-06-13 20:20:40 +0000458if exists("b:is_kornshell") || exists("b:is_bash")
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200459 syn keyword shStatement autoload bg false fc fg functions getopts hash history integer jobs let nohup printf r stop suspend times true type unalias whence
Bram Moolenaarc236c162008-07-13 17:41:49 +0000460 if exists("g:is_posix")
461 syn keyword shStatement command
462 else
463 syn keyword shStatement time
464 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000465
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000466" Useful bash Keywords: {{{1
467" =====================
Bram Moolenaar071d4272004-06-13 20:20:40 +0000468 if exists("b:is_bash")
469 syn keyword shStatement bind builtin dirs disown enable help local logout popd pushd shopt source
470 else
471 syn keyword shStatement login newgrp
472 endif
473endif
474
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000475" Synchronization: {{{1
476" ================
Bram Moolenaar071d4272004-06-13 20:20:40 +0000477if !exists("sh_minlines")
478 let sh_minlines = 200
479endif
480if !exists("sh_maxlines")
481 let sh_maxlines = 2 * sh_minlines
482endif
483exec "syn sync minlines=" . sh_minlines . " maxlines=" . sh_maxlines
484syn sync match shCaseEsacSync grouphere shCaseEsac "\<case\>"
485syn sync match shCaseEsacSync groupthere shCaseEsac "\<esac\>"
486syn sync match shDoSync grouphere shDo "\<do\>"
487syn sync match shDoSync groupthere shDo "\<done\>"
488syn sync match shForSync grouphere shFor "\<for\>"
489syn sync match shForSync groupthere shFor "\<in\>"
490syn sync match shIfSync grouphere shIf "\<if\>"
491syn sync match shIfSync groupthere shIf "\<fi\>"
492syn sync match shUntilSync grouphere shRepeat "\<until\>"
493syn sync match shWhileSync grouphere shRepeat "\<while\>"
494
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000495" Default Highlighting: {{{1
496" =====================
Bram Moolenaar071d4272004-06-13 20:20:40 +0000497hi def link shArithRegion shShellVariables
Bram Moolenaardf177f62005-02-22 08:39:57 +0000498hi def link shBeginHere shRedir
Bram Moolenaar071d4272004-06-13 20:20:40 +0000499hi def link shCaseBar shConditional
Bram Moolenaar071d4272004-06-13 20:20:40 +0000500hi def link shCaseCommandSub shCommandSub
501hi def link shCaseDoubleQuote shDoubleQuote
Bram Moolenaardf177f62005-02-22 08:39:57 +0000502hi def link shCaseIn shConditional
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200503hi def link shQuote shOperator
Bram Moolenaar071d4272004-06-13 20:20:40 +0000504hi def link shCaseSingleQuote shSingleQuote
505hi def link shCaseStart shConditional
506hi def link shCmdSubRegion shShellVariables
Bram Moolenaar5c736222010-01-06 20:54:52 +0100507hi def link shColon shComment
Bram Moolenaar071d4272004-06-13 20:20:40 +0000508hi def link shDerefOp shOperator
Bram Moolenaardf177f62005-02-22 08:39:57 +0000509hi def link shDerefPOL shDerefOp
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000510hi def link shDerefPPS shDerefOp
Bram Moolenaardf177f62005-02-22 08:39:57 +0000511hi def link shDeref shShellVariables
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200512hi def link shDerefDelim shOperator
Bram Moolenaar071d4272004-06-13 20:20:40 +0000513hi def link shDerefSimple shDeref
514hi def link shDerefSpecial shDeref
515hi def link shDerefString shDoubleQuote
Bram Moolenaardf177f62005-02-22 08:39:57 +0000516hi def link shDerefVar shDeref
Bram Moolenaar071d4272004-06-13 20:20:40 +0000517hi def link shDoubleQuote shString
518hi def link shEcho shString
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200519hi def link shEchoDelim shOperator
Bram Moolenaarc236c162008-07-13 17:41:49 +0000520hi def link shEchoQuote shString
Bram Moolenaar071d4272004-06-13 20:20:40 +0000521hi def link shEmbeddedEcho shString
Bram Moolenaarc236c162008-07-13 17:41:49 +0000522hi def link shEscape shCommandSub
Bram Moolenaare90ee312010-08-05 22:08:47 +0200523hi def link shExDoubleQuote shDoubleQuote
Bram Moolenaardf177f62005-02-22 08:39:57 +0000524hi def link shExSingleQuote shSingleQuote
Bram Moolenaarc236c162008-07-13 17:41:49 +0000525hi def link shFunction Function
Bram Moolenaar071d4272004-06-13 20:20:40 +0000526hi def link shHereDoc shString
Bram Moolenaardf177f62005-02-22 08:39:57 +0000527hi def link shHerePayload shHereDoc
Bram Moolenaar071d4272004-06-13 20:20:40 +0000528hi def link shLoop shStatement
Bram Moolenaar5c736222010-01-06 20:54:52 +0100529hi def link shMoreSpecial shSpecial
Bram Moolenaar071d4272004-06-13 20:20:40 +0000530hi def link shOption shCommandSub
531hi def link shPattern shString
Bram Moolenaarc236c162008-07-13 17:41:49 +0000532hi def link shParen shArithmetic
Bram Moolenaar071d4272004-06-13 20:20:40 +0000533hi def link shPosnParm shShellVariables
Bram Moolenaarc236c162008-07-13 17:41:49 +0000534hi def link shQuickComment shComment
Bram Moolenaar071d4272004-06-13 20:20:40 +0000535hi def link shRange shOperator
536hi def link shRedir shOperator
Bram Moolenaar4b22cdb2010-08-02 22:12:46 +0200537hi def link shSetListDelim shOperator
Bram Moolenaarc236c162008-07-13 17:41:49 +0000538hi def link shSetOption shOption
Bram Moolenaar071d4272004-06-13 20:20:40 +0000539hi def link shSingleQuote shString
540hi def link shSource shOperator
541hi def link shStringSpecial shSpecial
542hi def link shSubShRegion shOperator
543hi def link shTestOpr shConditional
Bram Moolenaar9964e462007-05-05 17:54:07 +0000544hi def link shTestPattern shString
545hi def link shTestDoubleQuote shString
546hi def link shTestSingleQuote shString
Bram Moolenaar071d4272004-06-13 20:20:40 +0000547hi def link shVariable shSetList
548hi def link shWrapLineOperator shOperator
549
550if exists("b:is_bash")
551 hi def link bashAdminStatement shStatement
552 hi def link bashSpecialVariables shShellVariables
553 hi def link bashStatement shStatement
Bram Moolenaarcd71fa32005-03-11 22:46:48 +0000554 hi def link shFunctionParen Delimiter
555 hi def link shFunctionDelim Delimiter
Bram Moolenaar071d4272004-06-13 20:20:40 +0000556endif
557if exists("b:is_kornshell")
558 hi def link kshSpecialVariables shShellVariables
559 hi def link kshStatement shStatement
Bram Moolenaarcd71fa32005-03-11 22:46:48 +0000560 hi def link shFunctionParen Delimiter
Bram Moolenaar071d4272004-06-13 20:20:40 +0000561endif
562
563hi def link shCaseError Error
564hi def link shCondError Error
565hi def link shCurlyError Error
566hi def link shDerefError Error
567hi def link shDerefOpError Error
568hi def link shDerefWordError Error
569hi def link shDoError Error
570hi def link shEsacError Error
571hi def link shIfError Error
572hi def link shInError Error
573hi def link shParenError Error
574hi def link shTestError Error
575if exists("b:is_kornshell")
576 hi def link shDTestError Error
577endif
578
579hi def link shArithmetic Special
580hi def link shCharClass Identifier
581hi def link shSnglCase Statement
582hi def link shCommandSub Special
583hi def link shComment Comment
584hi def link shConditional Conditional
Bram Moolenaar9964e462007-05-05 17:54:07 +0000585hi def link shCtrlSeq Special
Bram Moolenaar071d4272004-06-13 20:20:40 +0000586hi def link shExprRegion Delimiter
Bram Moolenaarcd71fa32005-03-11 22:46:48 +0000587hi def link shFunctionKey Function
Bram Moolenaar071d4272004-06-13 20:20:40 +0000588hi def link shFunctionName Function
589hi def link shNumber Number
590hi def link shOperator Operator
591hi def link shRepeat Repeat
592hi def link shSet Statement
593hi def link shSetList Identifier
594hi def link shShellVariables PreProc
595hi def link shSpecial Special
596hi def link shStatement Statement
597hi def link shString String
598hi def link shTodo Todo
599hi def link shAlias Identifier
600
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000601" Set Current Syntax: {{{1
602" ===================
Bram Moolenaar071d4272004-06-13 20:20:40 +0000603if exists("b:is_bash")
604 let b:current_syntax = "bash"
605elseif exists("b:is_kornshell")
606 let b:current_syntax = "ksh"
607else
608 let b:current_syntax = "sh"
609endif
610
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000611" vim: ts=16 fdm=marker