1" Vim syntax file 2" Language: MSDOS batch file (with NT command extensions) 3" Maintainer: Mike Williams <[email protected]> 4" Filenames: *.bat 5" Last Change: 6th September 2009 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" quit when a syntax file was already loaded 13if exists("b:current_syntax") 14 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 36syn match dosbatchOperator "\s[-+\*/%!~]\s" 37syn 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 43syn match dosbatchString "\"[^"]*\"" contains=dosbatchVariable,dosBatchArgument,dosbatchSpecialChar,@dosbatchNumber,@Spell 44syn match dosbatchString "\<echo\([^)>|]\|\^\@<=[)>|]\)*"lc=4 contains=dosbatchVariable,dosbatchArgument,dosbatchSpecialChar,@dosbatchNumber,@Spell 45syn 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 51syn 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 55syn 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*:\*\=[^=]*=[^%]*%" 69syn match dosbatchVariable "%\h\w*:\~[-]\=\d\+\(,[-]\=\d\+\)\=%" contains=dosbatchInteger 70syn match dosbatchVariable "!\h\w*!" 71syn match dosbatchVariable "!\h\w*:\*\=[^=]*=[^!]*!" 72syn match dosbatchVariable "!\h\w*:\~[-]\=\d\+\(,[-]\=\d\+\)\=!" contains=dosbatchInteger 73syn match dosbatchSet "\s\h\w*[+-]\==\{-1}" contains=dosbatchIdentifier,dosbatchOperator 74 75" Args to bat files and for loops, etc 76syn match dosbatchArgument "%\(\d\|\*\)" 77syn match dosbatchArgument "%[a-z]\>" 78if 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 91syn match dosbatchComment "^rem\($\|\s.*$\)"lc=3 contains=dosbatchTodo,dosbatchSpecialChar,@dosbatchNumber,dosbatchVariable,dosbatchArgument,@Spell 92syn match dosbatchComment "^@rem\($\|\s.*$\)"lc=4 contains=dosbatchTodo,@dosbatchNumber,dosbatchVariable,dosbatchArgument,@Spell 93syn match dosbatchComment "\srem\($\|\s.*$\)"lc=4 contains=dosbatchTodo,dosbatchSpecialChar,@dosbatchNumber,dosbatchVariable,dosbatchArgument,@Spell 94syn match dosbatchComment "\s@rem\($\|\s.*$\)"lc=5 contains=dosbatchTodo,@dosbatchNumber,dosbatchVariable,dosbatchArgument,@Spell 95syn match dosbatchComment "\s*:\s*:.*$" contains=dosbatchTodo,dosbatchSpecialChar,@dosbatchNumber,dosbatchVariable,dosbatchArgument,@Spell 96 97" Comments in ()'s - still to handle spaces before rem 98syn match dosbatchComment "(rem\([^)]\|\^\@<=)\)*"lc=4 contains=dosbatchTodo,@dosbatchNumber,dosbatchVariable,dosbatchArgument,@Spell 99 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. 111" Only when an item doesn't have highlighting yet 112command -nargs=+ HiLink hi def link <args> 113 114HiLink dosbatchTodo Todo 115 116HiLink dosbatchStatement Statement 117HiLink dosbatchCommands dosbatchStatement 118HiLink dosbatchLabel Label 119HiLink dosbatchConditional Conditional 120HiLink dosbatchRepeat Repeat 121 122HiLink dosbatchOperator Operator 123HiLink dosbatchEchoOperator dosbatchOperator 124HiLink dosbatchIfOperator dosbatchOperator 125 126HiLink dosbatchArgument Identifier 127HiLink dosbatchIdentifier Identifier 128HiLink dosbatchVariable dosbatchIdentifier 129 130HiLink dosbatchSpecialChar SpecialChar 131HiLink dosbatchString String 132HiLink dosbatchNumber Number 133HiLink dosbatchInteger dosbatchNumber 134HiLink dosbatchHex dosbatchNumber 135HiLink dosbatchBinary dosbatchNumber 136HiLink dosbatchOctal dosbatchNumber 137 138HiLink dosbatchComment Comment 139HiLink dosbatchImplicit Function 140 141HiLink dosbatchSwitch Special 142 143HiLink dosbatchCmd PreProc 144 145delcommand HiLink 146 147let b:current_syntax = "dosbatch" 148 149" vim: ts=8 150