blob: a75771bd2d5b528efc677e41b4d80b89f52c1aa9 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim syntax file
Bram Moolenaar938ae282023-02-20 20:44:55 +00002" Language: MS-DOS/Windows batch file (with NT command extensions)
3" Maintainer: Mike Williams <mrmrdubya@gmail.com>
Bram Moolenaar071d4272004-06-13 20:20:40 +00004" Filenames: *.bat
Bram Moolenaar938ae282023-02-20 20:44:55 +00005" Last Change: 12th February 2023
Bram Moolenaar071d4272004-06-13 20:20:40 +00006"
7" Options Flags:
8" dosbatch_cmdextversion - 1 = Windows NT, 2 = Windows 2000 [default]
Bram Moolenaar938ae282023-02-20 20:44:55 +00009" dosbatch_colons_comment - any value to treat :: as comment line
Bram Moolenaar071d4272004-06-13 20:20:40 +000010"
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 Moolenaar938ae282023-02-20 20:44:55 +000095if exists("dosbatch_colons_comment")
96 syn match dosbatchComment "\s*:\s*:.*$" contains=dosbatchTodo,dosbatchSpecialChar,@dosbatchNumber,dosbatchVariable,dosbatchArgument,@Spell
97else
98 syn match dosbatchError "\s*:\s*:.*$"
99endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000100
101" Comments in ()'s - still to handle spaces before rem
Bram Moolenaar864207d2008-06-24 22:14:38 +0000102syn match dosbatchComment "(rem\([^)]\|\^\@<=)\)*"lc=4 contains=dosbatchTodo,@dosbatchNumber,dosbatchVariable,dosbatchArgument,@Spell
Bram Moolenaar071d4272004-06-13 20:20:40 +0000103
104syn keyword dosbatchImplicit append assoc at attrib break cacls cd chcp chdir
105syn keyword dosbatchImplicit chkdsk chkntfs cls cmd color comp compact convert copy
106syn keyword dosbatchImplicit date del dir diskcomp diskcopy doskey echo endlocal
107syn keyword dosbatchImplicit erase fc find findstr format ftype
108syn keyword dosbatchImplicit graftabl help keyb label md mkdir mode more move
109syn keyword dosbatchImplicit path pause popd print prompt pushd rd recover rem
110syn keyword dosbatchImplicit ren rename replace restore rmdir set setlocal shift
111syn keyword dosbatchImplicit sort start subst time title tree type ver verify
112syn keyword dosbatchImplicit vol xcopy
113
114" Define the default highlighting.
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200115" Only when an item doesn't have highlighting yet
Bram Moolenaar071d4272004-06-13 20:20:40 +0000116
Bram Moolenaar938ae282023-02-20 20:44:55 +0000117hi def link dosbatchTodo Todo
118hi def link dosbatchError Error
Bram Moolenaar071d4272004-06-13 20:20:40 +0000119
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200120hi def link dosbatchStatement Statement
121hi def link dosbatchCommands dosbatchStatement
Bram Moolenaar938ae282023-02-20 20:44:55 +0000122hi def link dosbatchLabel Label
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200123hi def link dosbatchConditional Conditional
Bram Moolenaar938ae282023-02-20 20:44:55 +0000124hi def link dosbatchRepeat Repeat
Bram Moolenaar071d4272004-06-13 20:20:40 +0000125
Bram Moolenaar938ae282023-02-20 20:44:55 +0000126hi def link dosbatchOperator Operator
127hi def link dosbatchEchoOperator dosbatchOperator
128hi def link dosbatchIfOperator dosbatchOperator
Bram Moolenaar071d4272004-06-13 20:20:40 +0000129
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200130hi def link dosbatchArgument Identifier
Bram Moolenaar938ae282023-02-20 20:44:55 +0000131hi def link dosbatchIdentifier Identifier
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200132hi def link dosbatchVariable dosbatchIdentifier
Bram Moolenaar071d4272004-06-13 20:20:40 +0000133
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200134hi def link dosbatchSpecialChar SpecialChar
Bram Moolenaar938ae282023-02-20 20:44:55 +0000135hi def link dosbatchString String
136hi def link dosbatchNumber Number
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200137hi def link dosbatchInteger dosbatchNumber
138hi def link dosbatchHex dosbatchNumber
Bram Moolenaar938ae282023-02-20 20:44:55 +0000139hi def link dosbatchBinary dosbatchNumber
140hi def link dosbatchOctal dosbatchNumber
Bram Moolenaar071d4272004-06-13 20:20:40 +0000141
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200142hi def link dosbatchComment Comment
143hi def link dosbatchImplicit Function
Bram Moolenaar071d4272004-06-13 20:20:40 +0000144
Bram Moolenaar938ae282023-02-20 20:44:55 +0000145hi def link dosbatchSwitch Special
Bram Moolenaar071d4272004-06-13 20:20:40 +0000146
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200147hi def link dosbatchCmd PreProc
Bram Moolenaar071d4272004-06-13 20:20:40 +0000148
Bram Moolenaar071d4272004-06-13 20:20:40 +0000149
150let b:current_syntax = "dosbatch"
151
152" vim: ts=8