7
|
1 " Vim syntax file
|
|
2 " Language: MSDOS batch file (with NT command extensions)
|
|
3 " Maintainer: Mike Williams <mrw@eandem.co.uk>
|
|
4 " Filenames: *.bat
|
2034
|
5 " Last Change: 6th September 2009
|
7
|
6 " 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
|
|
14 if version < 600
|
|
15 syntax clear
|
|
16 elseif exists("b:current_syntax")
|
|
17 finish
|
|
18 endif
|
|
19
|
|
20 " Set default highlighting to Win2k
|
|
21 if !exists("dosbatch_cmdextversion")
|
|
22 let dosbatch_cmdextversion = 2
|
|
23 endif
|
|
24
|
|
25 " DOS bat files are case insensitive but case preserving!
|
|
26 syn case ignore
|
|
27
|
|
28 syn keyword dosbatchTodo contained TODO
|
|
29
|
|
30 " Dosbat keywords
|
|
31 syn keyword dosbatchStatement goto call exit
|
|
32 syn keyword dosbatchConditional if else
|
|
33 syn keyword dosbatchRepeat for
|
|
34
|
|
35 " Some operators - first lot are case sensitive!
|
|
36 syn case match
|
|
37 syn keyword dosbatchOperator EQU NEQ LSS LEQ GTR GEQ
|
|
38 syn case ignore
|
2034
|
39 syn match dosbatchOperator "\s[-+\*/%!~]\s"
|
7
|
40 syn match dosbatchOperator "="
|
|
41 syn match dosbatchOperator "[-+\*/%]="
|
|
42 syn match dosbatchOperator "\s\(&\||\|^\|<<\|>>\)=\=\s"
|
|
43 syn 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
|
1623
|
46 syn match dosbatchString "\"[^"]*\"" contains=dosbatchVariable,dosBatchArgument,dosbatchSpecialChar,@dosbatchNumber,@Spell
|
|
47 syn match dosbatchString "\<echo\([^)>|]\|\^\@<=[)>|]\)*"lc=4 contains=dosbatchVariable,dosbatchArgument,dosbatchSpecialChar,@dosbatchNumber,@Spell
|
7
|
48 syn match dosbatchEchoOperator "\<echo\s\+\(on\|off\)\s*$"lc=4
|
|
49
|
|
50 " For embedded commands
|
|
51 syn 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
|
2034
|
54 syn match dosbatchInteger "[[:space:]=(/:,!~-]\d\+"lc=1
|
|
55 syn match dosbatchHex "[[:space:]=(/:,!~-]0x\x\+"lc=1
|
|
56 syn match dosbatchBinary "[[:space:]=(/:,!~-]0b[01]\+"lc=1
|
|
57 syn match dosbatchOctal "[[:space:]=(/:,!~-]0\o\+"lc=1
|
7
|
58 syn cluster dosbatchNumber contains=dosbatchInteger,dosbatchHex,dosbatchBinary,dosbatchOctal
|
|
59
|
|
60 " Command line switches
|
|
61 syn match dosbatchSwitch "/\(\a\+\|?\)"
|
|
62
|
|
63 " Various special escaped char formats
|
|
64 syn match dosbatchSpecialChar "\^[&|()<>^]"
|
|
65 syn match dosbatchSpecialChar "\$[a-hl-npqstv_$+]"
|
|
66 syn match dosbatchSpecialChar "%%"
|
|
67
|
|
68 " Environment variables
|
|
69 syn match dosbatchIdentifier contained "\s\h\w*\>"
|
|
70 syn match dosbatchVariable "%\h\w*%"
|
|
71 syn match dosbatchVariable "%\h\w*:\*\=[^=]*=[^%]*%"
|
2034
|
72 syn match dosbatchVariable "%\h\w*:\~[-]\=\d\+\(,[-]\=\d\+\)\=%" contains=dosbatchInteger
|
7
|
73 syn match dosbatchVariable "!\h\w*!"
|
2034
|
74 syn match dosbatchVariable "!\h\w*:\*\=[^=]*=[^!]*!"
|
|
75 syn match dosbatchVariable "!\h\w*:\~[-]\=\d\+\(,[-]\=\d\+\)\=!" contains=dosbatchInteger
|
7
|
76 syn match dosbatchSet "\s\h\w*[+-]\==\{-1}" contains=dosbatchIdentifier,dosbatchOperator
|
|
77
|
|
78 " Args to bat files and for loops, etc
|
|
79 syn match dosbatchArgument "%\(\d\|\*\)"
|
2034
|
80 syn match dosbatchArgument "%[a-z]\>"
|
7
|
81 if dosbatch_cmdextversion == 1
|
|
82 syn match dosbatchArgument "%\~[fdpnxs]\+\(\($PATH:\)\=[a-z]\|\d\)\>"
|
|
83 else
|
|
84 syn match dosbatchArgument "%\~[fdpnxsatz]\+\(\($PATH:\)\=[a-z]\|\d\)\>"
|
|
85 endif
|
|
86
|
|
87 " Line labels
|
|
88 syn match dosbatchLabel "^\s*:\s*\h\w*\>"
|
|
89 syn match dosbatchLabel "\<\(goto\|call\)\s\+:\h\w*\>"lc=4
|
|
90 syn match dosbatchLabel "\<goto\s\+\h\w*\>"lc=4
|
|
91 syn match dosbatchLabel ":\h\w*\>"
|
|
92
|
|
93 " Comments - usual rem but also two colons as first non-space is an idiom
|
1623
|
94 syn match dosbatchComment "^rem\($\|\s.*$\)"lc=3 contains=dosbatchTodo,dosbatchSpecialChar,@dosbatchNumber,dosbatchVariable,dosbatchArgument,@Spell
|
2034
|
95 syn match dosbatchComment "^@rem\($\|\s.*$\)"lc=4 contains=dosbatchTodo,@dosbatchNumber,dosbatchVariable,dosbatchArgument,@Spell
|
1623
|
96 syn match dosbatchComment "\srem\($\|\s.*$\)"lc=4 contains=dosbatchTodo,dosbatchSpecialChar,@dosbatchNumber,dosbatchVariable,dosbatchArgument,@Spell
|
2034
|
97 syn match dosbatchComment "\s@rem\($\|\s.*$\)"lc=5 contains=dosbatchTodo,@dosbatchNumber,dosbatchVariable,dosbatchArgument,@Spell
|
1623
|
98 syn match dosbatchComment "\s*:\s*:.*$" contains=dosbatchTodo,dosbatchSpecialChar,@dosbatchNumber,dosbatchVariable,dosbatchArgument,@Spell
|
7
|
99
|
|
100 " Comments in ()'s - still to handle spaces before rem
|
1623
|
101 syn match dosbatchComment "(rem\([^)]\|\^\@<=)\)*"lc=4 contains=dosbatchTodo,@dosbatchNumber,dosbatchVariable,dosbatchArgument,@Spell
|
7
|
102
|
|
103 syn keyword dosbatchImplicit append assoc at attrib break cacls cd chcp chdir
|
|
104 syn keyword dosbatchImplicit chkdsk chkntfs cls cmd color comp compact convert copy
|
|
105 syn keyword dosbatchImplicit date del dir diskcomp diskcopy doskey echo endlocal
|
|
106 syn keyword dosbatchImplicit erase fc find findstr format ftype
|
|
107 syn keyword dosbatchImplicit graftabl help keyb label md mkdir mode more move
|
|
108 syn keyword dosbatchImplicit path pause popd print prompt pushd rd recover rem
|
|
109 syn keyword dosbatchImplicit ren rename replace restore rmdir set setlocal shift
|
|
110 syn keyword dosbatchImplicit sort start subst time title tree type ver verify
|
|
111 syn 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
|
|
116 if 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
|
1623
|
132 HiLink dosbatchOperator Operator
|
|
133 HiLink dosbatchEchoOperator dosbatchOperator
|
|
134 HiLink dosbatchIfOperator dosbatchOperator
|
7
|
135
|
|
136 HiLink dosbatchArgument Identifier
|
1623
|
137 HiLink dosbatchIdentifier Identifier
|
7
|
138 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
|
|
156 endif
|
|
157
|
|
158 let b:current_syntax = "dosbatch"
|
|
159
|
|
160 " vim: ts=8
|