blob: b7f49ca4e9d5e62cbd9e6eb6d401a9b401ab5e6a [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
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
112command -nargs=+ HiLink hi def link <args>
Bram Moolenaar071d4272004-06-13 20:20:40 +0000113
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200114HiLink dosbatchTodo Todo
Bram Moolenaar071d4272004-06-13 20:20:40 +0000115
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200116HiLink dosbatchStatement Statement
117HiLink dosbatchCommands dosbatchStatement
118HiLink dosbatchLabel Label
119HiLink dosbatchConditional Conditional
120HiLink dosbatchRepeat Repeat
Bram Moolenaar071d4272004-06-13 20:20:40 +0000121
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200122HiLink dosbatchOperator Operator
123HiLink dosbatchEchoOperator dosbatchOperator
124HiLink dosbatchIfOperator dosbatchOperator
Bram Moolenaar071d4272004-06-13 20:20:40 +0000125
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200126HiLink dosbatchArgument Identifier
127HiLink dosbatchIdentifier Identifier
128HiLink dosbatchVariable dosbatchIdentifier
Bram Moolenaar071d4272004-06-13 20:20:40 +0000129
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200130HiLink dosbatchSpecialChar SpecialChar
131HiLink dosbatchString String
132HiLink dosbatchNumber Number
133HiLink dosbatchInteger dosbatchNumber
134HiLink dosbatchHex dosbatchNumber
135HiLink dosbatchBinary dosbatchNumber
136HiLink dosbatchOctal dosbatchNumber
Bram Moolenaar071d4272004-06-13 20:20:40 +0000137
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200138HiLink dosbatchComment Comment
139HiLink dosbatchImplicit Function
Bram Moolenaar071d4272004-06-13 20:20:40 +0000140
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200141HiLink dosbatchSwitch Special
Bram Moolenaar071d4272004-06-13 20:20:40 +0000142
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200143HiLink dosbatchCmd PreProc
Bram Moolenaar071d4272004-06-13 20:20:40 +0000144
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200145delcommand HiLink
Bram Moolenaar071d4272004-06-13 20:20:40 +0000146
147let b:current_syntax = "dosbatch"
148
149" vim: ts=8