blob: f003a65909f731422b7177089d8983fd79a69b47 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim syntax file
Bram Moolenaar6c391a72021-09-09 21:55:11 +02002" Language: MS-DOS batch file (with NT command extensions)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003" 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
Bram Moolenaar89bcfda2016-08-30 23:26:57 +020012" quit when a syntax file was already loaded
13if exists("b:current_syntax")
Bram Moolenaar071d4272004-06-13 20:20:40 +000014 finish
15endif
16
17" Set default highlighting to Win2k
18if !exists("dosbatch_cmdextversion")
19 let dosbatch_cmdextversion = 2
20endif
21
22" DOS bat files are case insensitive but case preserving!
23syn case ignore
24
25syn keyword dosbatchTodo contained TODO
26
27" Dosbat keywords
28syn keyword dosbatchStatement goto call exit
29syn keyword dosbatchConditional if else
30syn keyword dosbatchRepeat for
31
32" Some operators - first lot are case sensitive!
33syn case match
34syn keyword dosbatchOperator EQU NEQ LSS LEQ GTR GEQ
35syn case ignore
Bram Moolenaar5c736222010-01-06 20:54:52 +010036syn match dosbatchOperator "\s[-+\*/%!~]\s"
Bram Moolenaar071d4272004-06-13 20:20:40 +000037syn match dosbatchOperator "="
38syn match dosbatchOperator "[-+\*/%]="
39syn match dosbatchOperator "\s\(&\||\|^\|<<\|>>\)=\=\s"
40syn match dosbatchIfOperator "if\s\+\(\(not\)\=\s\+\)\=\(exist\|defined\|errorlevel\|cmdextversion\)\="lc=2
41
42" String - using "'s is a convenience rather than a requirement outside of FOR
Bram Moolenaar864207d2008-06-24 22:14:38 +000043syn match dosbatchString "\"[^"]*\"" contains=dosbatchVariable,dosBatchArgument,dosbatchSpecialChar,@dosbatchNumber,@Spell
44syn match dosbatchString "\<echo\([^)>|]\|\^\@<=[)>|]\)*"lc=4 contains=dosbatchVariable,dosbatchArgument,dosbatchSpecialChar,@dosbatchNumber,@Spell
Bram Moolenaar071d4272004-06-13 20:20:40 +000045syn match dosbatchEchoOperator "\<echo\s\+\(on\|off\)\s*$"lc=4
46
47" For embedded commands
48syn match dosbatchCmd "(\s*'[^']*'"lc=1 contains=dosbatchString,dosbatchVariable,dosBatchArgument,@dosbatchNumber,dosbatchImplicit,dosbatchStatement,dosbatchConditional,dosbatchRepeat,dosbatchOperator
49
50" Numbers - surround with ws to not include in dir and filenames
Bram Moolenaar5c736222010-01-06 20:54:52 +010051syn match dosbatchInteger "[[:space:]=(/:,!~-]\d\+"lc=1
52syn match dosbatchHex "[[:space:]=(/:,!~-]0x\x\+"lc=1
53syn match dosbatchBinary "[[:space:]=(/:,!~-]0b[01]\+"lc=1
54syn match dosbatchOctal "[[:space:]=(/:,!~-]0\o\+"lc=1
Bram Moolenaar071d4272004-06-13 20:20:40 +000055syn cluster dosbatchNumber contains=dosbatchInteger,dosbatchHex,dosbatchBinary,dosbatchOctal
56
57" Command line switches
58syn match dosbatchSwitch "/\(\a\+\|?\)"
59
60" Various special escaped char formats
61syn match dosbatchSpecialChar "\^[&|()<>^]"
62syn match dosbatchSpecialChar "\$[a-hl-npqstv_$+]"
63syn match dosbatchSpecialChar "%%"
64
65" Environment variables
66syn match dosbatchIdentifier contained "\s\h\w*\>"
67syn match dosbatchVariable "%\h\w*%"
68syn match dosbatchVariable "%\h\w*:\*\=[^=]*=[^%]*%"
Bram Moolenaar5c736222010-01-06 20:54:52 +010069syn match dosbatchVariable "%\h\w*:\~[-]\=\d\+\(,[-]\=\d\+\)\=%" contains=dosbatchInteger
Bram Moolenaar071d4272004-06-13 20:20:40 +000070syn match dosbatchVariable "!\h\w*!"
Bram Moolenaar5c736222010-01-06 20:54:52 +010071syn match dosbatchVariable "!\h\w*:\*\=[^=]*=[^!]*!"
72syn match dosbatchVariable "!\h\w*:\~[-]\=\d\+\(,[-]\=\d\+\)\=!" contains=dosbatchInteger
Bram Moolenaar071d4272004-06-13 20:20:40 +000073syn match dosbatchSet "\s\h\w*[+-]\==\{-1}" contains=dosbatchIdentifier,dosbatchOperator
74
75" Args to bat files and for loops, etc
76syn match dosbatchArgument "%\(\d\|\*\)"
Bram Moolenaar5c736222010-01-06 20:54:52 +010077syn match dosbatchArgument "%[a-z]\>"
Bram Moolenaar071d4272004-06-13 20:20:40 +000078if dosbatch_cmdextversion == 1
79 syn match dosbatchArgument "%\~[fdpnxs]\+\(\($PATH:\)\=[a-z]\|\d\)\>"
80else
81 syn match dosbatchArgument "%\~[fdpnxsatz]\+\(\($PATH:\)\=[a-z]\|\d\)\>"
82endif
83
84" Line labels
85syn match dosbatchLabel "^\s*:\s*\h\w*\>"
86syn match dosbatchLabel "\<\(goto\|call\)\s\+:\h\w*\>"lc=4
87syn match dosbatchLabel "\<goto\s\+\h\w*\>"lc=4
88syn match dosbatchLabel ":\h\w*\>"
89
90" Comments - usual rem but also two colons as first non-space is an idiom
Bram Moolenaar864207d2008-06-24 22:14:38 +000091syn match dosbatchComment "^rem\($\|\s.*$\)"lc=3 contains=dosbatchTodo,dosbatchSpecialChar,@dosbatchNumber,dosbatchVariable,dosbatchArgument,@Spell
Bram Moolenaar5c736222010-01-06 20:54:52 +010092syn match dosbatchComment "^@rem\($\|\s.*$\)"lc=4 contains=dosbatchTodo,@dosbatchNumber,dosbatchVariable,dosbatchArgument,@Spell
Bram Moolenaar864207d2008-06-24 22:14:38 +000093syn match dosbatchComment "\srem\($\|\s.*$\)"lc=4 contains=dosbatchTodo,dosbatchSpecialChar,@dosbatchNumber,dosbatchVariable,dosbatchArgument,@Spell
Bram Moolenaar5c736222010-01-06 20:54:52 +010094syn match dosbatchComment "\s@rem\($\|\s.*$\)"lc=5 contains=dosbatchTodo,@dosbatchNumber,dosbatchVariable,dosbatchArgument,@Spell
Bram Moolenaar864207d2008-06-24 22:14:38 +000095syn match dosbatchComment "\s*:\s*:.*$" contains=dosbatchTodo,dosbatchSpecialChar,@dosbatchNumber,dosbatchVariable,dosbatchArgument,@Spell
Bram Moolenaar071d4272004-06-13 20:20:40 +000096
97" Comments in ()'s - still to handle spaces before rem
Bram Moolenaar864207d2008-06-24 22:14:38 +000098syn match dosbatchComment "(rem\([^)]\|\^\@<=)\)*"lc=4 contains=dosbatchTodo,@dosbatchNumber,dosbatchVariable,dosbatchArgument,@Spell
Bram Moolenaar071d4272004-06-13 20:20:40 +000099
100syn keyword dosbatchImplicit append assoc at attrib break cacls cd chcp chdir
101syn keyword dosbatchImplicit chkdsk chkntfs cls cmd color comp compact convert copy
102syn keyword dosbatchImplicit date del dir diskcomp diskcopy doskey echo endlocal
103syn keyword dosbatchImplicit erase fc find findstr format ftype
104syn keyword dosbatchImplicit graftabl help keyb label md mkdir mode more move
105syn keyword dosbatchImplicit path pause popd print prompt pushd rd recover rem
106syn keyword dosbatchImplicit ren rename replace restore rmdir set setlocal shift
107syn keyword dosbatchImplicit sort start subst time title tree type ver verify
108syn keyword dosbatchImplicit vol xcopy
109
110" Define the default highlighting.
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200111" Only when an item doesn't have highlighting yet
Bram Moolenaar071d4272004-06-13 20:20:40 +0000112
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200113hi def link dosbatchTodo Todo
Bram Moolenaar071d4272004-06-13 20:20:40 +0000114
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200115hi def link dosbatchStatement Statement
116hi def link dosbatchCommands dosbatchStatement
117hi def link dosbatchLabel Label
118hi def link dosbatchConditional Conditional
119hi def link dosbatchRepeat Repeat
Bram Moolenaar071d4272004-06-13 20:20:40 +0000120
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200121hi def link dosbatchOperator Operator
122hi def link dosbatchEchoOperator dosbatchOperator
123hi def link dosbatchIfOperator dosbatchOperator
Bram Moolenaar071d4272004-06-13 20:20:40 +0000124
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200125hi def link dosbatchArgument Identifier
126hi def link dosbatchIdentifier Identifier
127hi def link dosbatchVariable dosbatchIdentifier
Bram Moolenaar071d4272004-06-13 20:20:40 +0000128
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200129hi def link dosbatchSpecialChar SpecialChar
130hi def link dosbatchString String
131hi def link dosbatchNumber Number
132hi def link dosbatchInteger dosbatchNumber
133hi def link dosbatchHex dosbatchNumber
134hi def link dosbatchBinary dosbatchNumber
135hi def link dosbatchOctal dosbatchNumber
Bram Moolenaar071d4272004-06-13 20:20:40 +0000136
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200137hi def link dosbatchComment Comment
138hi def link dosbatchImplicit Function
Bram Moolenaar071d4272004-06-13 20:20:40 +0000139
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200140hi def link dosbatchSwitch Special
Bram Moolenaar071d4272004-06-13 20:20:40 +0000141
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200142hi def link dosbatchCmd PreProc
Bram Moolenaar071d4272004-06-13 20:20:40 +0000143
Bram Moolenaar071d4272004-06-13 20:20:40 +0000144
145let b:current_syntax = "dosbatch"
146
147" vim: ts=8