blob: 8c012993347184294d9ea1ad0b38ea98b435724e [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim syntax file
2" Language: MSDOS batch file (with NT command extensions)
3" Maintainer: Mike Williams <mrw@eandem.co.uk>
4" Filenames: *.bat
Bram Moolenaar864207d2008-06-24 22:14:38 +00005" Last Change: 10th May 2008
Bram Moolenaar071d4272004-06-13 20:20:40 +00006" Web Page: http://www.eandem.co.uk/mrw/vim
7"
8" Options Flags:
9" dosbatch_cmdextversion - 1 = Windows NT, 2 = Windows 2000 [default]
10"
11
12" For version 5.x: Clear all syntax items
13" For version 6.x: Quit when a syntax file was already loaded
14if version < 600
15 syntax clear
16elseif exists("b:current_syntax")
17 finish
18endif
19
20" Set default highlighting to Win2k
21if !exists("dosbatch_cmdextversion")
22 let dosbatch_cmdextversion = 2
23endif
24
25" DOS bat files are case insensitive but case preserving!
26syn case ignore
27
28syn keyword dosbatchTodo contained TODO
29
30" Dosbat keywords
31syn keyword dosbatchStatement goto call exit
32syn keyword dosbatchConditional if else
33syn keyword dosbatchRepeat for
34
35" Some operators - first lot are case sensitive!
36syn case match
37syn keyword dosbatchOperator EQU NEQ LSS LEQ GTR GEQ
38syn case ignore
39syn match dosbatchOperator "\s[-+\*/%]\s"
40syn match dosbatchOperator "="
41syn match dosbatchOperator "[-+\*/%]="
42syn match dosbatchOperator "\s\(&\||\|^\|<<\|>>\)=\=\s"
43syn match dosbatchIfOperator "if\s\+\(\(not\)\=\s\+\)\=\(exist\|defined\|errorlevel\|cmdextversion\)\="lc=2
44
45" String - using "'s is a convenience rather than a requirement outside of FOR
Bram Moolenaar864207d2008-06-24 22:14:38 +000046syn match dosbatchString "\"[^"]*\"" contains=dosbatchVariable,dosBatchArgument,dosbatchSpecialChar,@dosbatchNumber,@Spell
47syn match dosbatchString "\<echo\([^)>|]\|\^\@<=[)>|]\)*"lc=4 contains=dosbatchVariable,dosbatchArgument,dosbatchSpecialChar,@dosbatchNumber,@Spell
Bram Moolenaar071d4272004-06-13 20:20:40 +000048syn match dosbatchEchoOperator "\<echo\s\+\(on\|off\)\s*$"lc=4
49
50" For embedded commands
51syn match dosbatchCmd "(\s*'[^']*'"lc=1 contains=dosbatchString,dosbatchVariable,dosBatchArgument,@dosbatchNumber,dosbatchImplicit,dosbatchStatement,dosbatchConditional,dosbatchRepeat,dosbatchOperator
52
53" Numbers - surround with ws to not include in dir and filenames
54syn match dosbatchInteger "[[:space:]=(/:]\d\+"lc=1
55syn match dosbatchHex "[[:space:]=(/:]0x\x\+"lc=1
56syn match dosbatchBinary "[[:space:]=(/:]0b[01]\+"lc=1
57syn match dosbatchOctal "[[:space:]=(/:]0\o\+"lc=1
58syn cluster dosbatchNumber contains=dosbatchInteger,dosbatchHex,dosbatchBinary,dosbatchOctal
59
60" Command line switches
61syn match dosbatchSwitch "/\(\a\+\|?\)"
62
63" Various special escaped char formats
64syn match dosbatchSpecialChar "\^[&|()<>^]"
65syn match dosbatchSpecialChar "\$[a-hl-npqstv_$+]"
66syn match dosbatchSpecialChar "%%"
67
68" Environment variables
69syn match dosbatchIdentifier contained "\s\h\w*\>"
70syn match dosbatchVariable "%\h\w*%"
71syn match dosbatchVariable "%\h\w*:\*\=[^=]*=[^%]*%"
72syn match dosbatchVariable "%\h\w*:\~\d\+,\d\+%" contains=dosbatchInteger
73syn match dosbatchVariable "!\h\w*!"
74syn match dosbatchVariable "!\h\w*:\*\=[^=]*=[^%]*!"
75syn match dosbatchVariable "!\h\w*:\~\d\+,\d\+!" contains=dosbatchInteger
76syn match dosbatchSet "\s\h\w*[+-]\==\{-1}" contains=dosbatchIdentifier,dosbatchOperator
77
78" Args to bat files and for loops, etc
79syn match dosbatchArgument "%\(\d\|\*\)"
80syn match dosbatchArgument "%%[a-z]\>"
81if dosbatch_cmdextversion == 1
82 syn match dosbatchArgument "%\~[fdpnxs]\+\(\($PATH:\)\=[a-z]\|\d\)\>"
83else
84 syn match dosbatchArgument "%\~[fdpnxsatz]\+\(\($PATH:\)\=[a-z]\|\d\)\>"
85endif
86
87" Line labels
88syn match dosbatchLabel "^\s*:\s*\h\w*\>"
89syn match dosbatchLabel "\<\(goto\|call\)\s\+:\h\w*\>"lc=4
90syn match dosbatchLabel "\<goto\s\+\h\w*\>"lc=4
91syn match dosbatchLabel ":\h\w*\>"
92
93" Comments - usual rem but also two colons as first non-space is an idiom
Bram Moolenaar864207d2008-06-24 22:14:38 +000094syn match dosbatchComment "^rem\($\|\s.*$\)"lc=3 contains=dosbatchTodo,dosbatchSpecialChar,@dosbatchNumber,dosbatchVariable,dosbatchArgument,@Spell
95syn match dosbatchComment "\srem\($\|\s.*$\)"lc=4 contains=dosbatchTodo,dosbatchSpecialChar,@dosbatchNumber,dosbatchVariable,dosbatchArgument,@Spell
96syn match dosbatchComment "\s*:\s*:.*$" contains=dosbatchTodo,dosbatchSpecialChar,@dosbatchNumber,dosbatchVariable,dosbatchArgument,@Spell
Bram Moolenaar071d4272004-06-13 20:20:40 +000097
98" Comments in ()'s - still to handle spaces before rem
Bram Moolenaar864207d2008-06-24 22:14:38 +000099syn match dosbatchComment "(rem\([^)]\|\^\@<=)\)*"lc=4 contains=dosbatchTodo,@dosbatchNumber,dosbatchVariable,dosbatchArgument,@Spell
Bram Moolenaar071d4272004-06-13 20:20:40 +0000100
101syn keyword dosbatchImplicit append assoc at attrib break cacls cd chcp chdir
102syn keyword dosbatchImplicit chkdsk chkntfs cls cmd color comp compact convert copy
103syn keyword dosbatchImplicit date del dir diskcomp diskcopy doskey echo endlocal
104syn keyword dosbatchImplicit erase fc find findstr format ftype
105syn keyword dosbatchImplicit graftabl help keyb label md mkdir mode more move
106syn keyword dosbatchImplicit path pause popd print prompt pushd rd recover rem
107syn keyword dosbatchImplicit ren rename replace restore rmdir set setlocal shift
108syn keyword dosbatchImplicit sort start subst time title tree type ver verify
109syn keyword dosbatchImplicit vol xcopy
110
111" Define the default highlighting.
112" For version 5.7 and earlier: only when not done already
113" For version 5.8 and later: only when an item doesn't have highlighting yet
114if version >= 508 || !exists("did_dosbatch_syntax_inits")
115 if version < 508
116 let did_dosbatch_syntax_inits = 1
117 command -nargs=+ HiLink hi link <args>
118 else
119 command -nargs=+ HiLink hi def link <args>
120 endif
121
122 HiLink dosbatchTodo Todo
123
124 HiLink dosbatchStatement Statement
125 HiLink dosbatchCommands dosbatchStatement
126 HiLink dosbatchLabel Label
127 HiLink dosbatchConditional Conditional
128 HiLink dosbatchRepeat Repeat
129
Bram Moolenaar864207d2008-06-24 22:14:38 +0000130 HiLink dosbatchOperator Operator
131 HiLink dosbatchEchoOperator dosbatchOperator
132 HiLink dosbatchIfOperator dosbatchOperator
Bram Moolenaar071d4272004-06-13 20:20:40 +0000133
134 HiLink dosbatchArgument Identifier
Bram Moolenaar864207d2008-06-24 22:14:38 +0000135 HiLink dosbatchIdentifier Identifier
Bram Moolenaar071d4272004-06-13 20:20:40 +0000136 HiLink dosbatchVariable dosbatchIdentifier
137
138 HiLink dosbatchSpecialChar SpecialChar
139 HiLink dosbatchString String
140 HiLink dosbatchNumber Number
141 HiLink dosbatchInteger dosbatchNumber
142 HiLink dosbatchHex dosbatchNumber
143 HiLink dosbatchBinary dosbatchNumber
144 HiLink dosbatchOctal dosbatchNumber
145
146 HiLink dosbatchComment Comment
147 HiLink dosbatchImplicit Function
148
149 HiLink dosbatchSwitch Special
150
151 HiLink dosbatchCmd PreProc
152
153 delcommand HiLink
154endif
155
156let b:current_syntax = "dosbatch"
157
158" vim: ts=8