blob: d9b1aa6703fd719dee8f86c1032c1227b487fef1 [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 Moolenaar5c736222010-01-06 20:54:52 +01005" Last Change: 6th September 2009
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
Bram Moolenaar5c736222010-01-06 20:54:52 +010039syn match dosbatchOperator "\s[-+\*/%!~]\s"
Bram Moolenaar071d4272004-06-13 20:20:40 +000040syn 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
Bram Moolenaar5c736222010-01-06 20:54:52 +010054syn 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
Bram Moolenaar071d4272004-06-13 20:20:40 +000058syn 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*:\*\=[^=]*=[^%]*%"
Bram Moolenaar5c736222010-01-06 20:54:52 +010072syn match dosbatchVariable "%\h\w*:\~[-]\=\d\+\(,[-]\=\d\+\)\=%" contains=dosbatchInteger
Bram Moolenaar071d4272004-06-13 20:20:40 +000073syn match dosbatchVariable "!\h\w*!"
Bram Moolenaar5c736222010-01-06 20:54:52 +010074syn match dosbatchVariable "!\h\w*:\*\=[^=]*=[^!]*!"
75syn match dosbatchVariable "!\h\w*:\~[-]\=\d\+\(,[-]\=\d\+\)\=!" contains=dosbatchInteger
Bram Moolenaar071d4272004-06-13 20:20:40 +000076syn match dosbatchSet "\s\h\w*[+-]\==\{-1}" contains=dosbatchIdentifier,dosbatchOperator
77
78" Args to bat files and for loops, etc
79syn match dosbatchArgument "%\(\d\|\*\)"
Bram Moolenaar5c736222010-01-06 20:54:52 +010080syn match dosbatchArgument "%[a-z]\>"
Bram Moolenaar071d4272004-06-13 20:20:40 +000081if 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
Bram Moolenaar5c736222010-01-06 20:54:52 +010095syn match dosbatchComment "^@rem\($\|\s.*$\)"lc=4 contains=dosbatchTodo,@dosbatchNumber,dosbatchVariable,dosbatchArgument,@Spell
Bram Moolenaar864207d2008-06-24 22:14:38 +000096syn match dosbatchComment "\srem\($\|\s.*$\)"lc=4 contains=dosbatchTodo,dosbatchSpecialChar,@dosbatchNumber,dosbatchVariable,dosbatchArgument,@Spell
Bram Moolenaar5c736222010-01-06 20:54:52 +010097syn match dosbatchComment "\s@rem\($\|\s.*$\)"lc=5 contains=dosbatchTodo,@dosbatchNumber,dosbatchVariable,dosbatchArgument,@Spell
Bram Moolenaar864207d2008-06-24 22:14:38 +000098syn match dosbatchComment "\s*:\s*:.*$" contains=dosbatchTodo,dosbatchSpecialChar,@dosbatchNumber,dosbatchVariable,dosbatchArgument,@Spell
Bram Moolenaar071d4272004-06-13 20:20:40 +000099
100" Comments in ()'s - still to handle spaces before rem
Bram Moolenaar864207d2008-06-24 22:14:38 +0000101syn match dosbatchComment "(rem\([^)]\|\^\@<=)\)*"lc=4 contains=dosbatchTodo,@dosbatchNumber,dosbatchVariable,dosbatchArgument,@Spell
Bram Moolenaar071d4272004-06-13 20:20:40 +0000102
103syn keyword dosbatchImplicit append assoc at attrib break cacls cd chcp chdir
104syn keyword dosbatchImplicit chkdsk chkntfs cls cmd color comp compact convert copy
105syn keyword dosbatchImplicit date del dir diskcomp diskcopy doskey echo endlocal
106syn keyword dosbatchImplicit erase fc find findstr format ftype
107syn keyword dosbatchImplicit graftabl help keyb label md mkdir mode more move
108syn keyword dosbatchImplicit path pause popd print prompt pushd rd recover rem
109syn keyword dosbatchImplicit ren rename replace restore rmdir set setlocal shift
110syn keyword dosbatchImplicit sort start subst time title tree type ver verify
111syn keyword dosbatchImplicit vol xcopy
112
113" Define the default highlighting.
114" For version 5.7 and earlier: only when not done already
115" For version 5.8 and later: only when an item doesn't have highlighting yet
116if version >= 508 || !exists("did_dosbatch_syntax_inits")
117 if version < 508
118 let did_dosbatch_syntax_inits = 1
119 command -nargs=+ HiLink hi link <args>
120 else
121 command -nargs=+ HiLink hi def link <args>
122 endif
123
124 HiLink dosbatchTodo Todo
125
126 HiLink dosbatchStatement Statement
127 HiLink dosbatchCommands dosbatchStatement
128 HiLink dosbatchLabel Label
129 HiLink dosbatchConditional Conditional
130 HiLink dosbatchRepeat Repeat
131
Bram Moolenaar864207d2008-06-24 22:14:38 +0000132 HiLink dosbatchOperator Operator
133 HiLink dosbatchEchoOperator dosbatchOperator
134 HiLink dosbatchIfOperator dosbatchOperator
Bram Moolenaar071d4272004-06-13 20:20:40 +0000135
136 HiLink dosbatchArgument Identifier
Bram Moolenaar864207d2008-06-24 22:14:38 +0000137 HiLink dosbatchIdentifier Identifier
Bram Moolenaar071d4272004-06-13 20:20:40 +0000138 HiLink dosbatchVariable dosbatchIdentifier
139
140 HiLink dosbatchSpecialChar SpecialChar
141 HiLink dosbatchString String
142 HiLink dosbatchNumber Number
143 HiLink dosbatchInteger dosbatchNumber
144 HiLink dosbatchHex dosbatchNumber
145 HiLink dosbatchBinary dosbatchNumber
146 HiLink dosbatchOctal dosbatchNumber
147
148 HiLink dosbatchComment Comment
149 HiLink dosbatchImplicit Function
150
151 HiLink dosbatchSwitch Special
152
153 HiLink dosbatchCmd PreProc
154
155 delcommand HiLink
156endif
157
158let b:current_syntax = "dosbatch"
159
160" vim: ts=8