1*130cbfc3SBram Moolenaar" Vim syntax file 2*130cbfc3SBram Moolenaar" Language: Windows PowerShell 3*130cbfc3SBram Moolenaar" URL: https://github.com/PProvost/vim-ps1 4*130cbfc3SBram Moolenaar" Last Change: 2020 Nov 24 5*130cbfc3SBram Moolenaar" 6*130cbfc3SBram Moolenaar" The following settings are available for tuning syntax highlighting: 7*130cbfc3SBram Moolenaar" let ps1_nofold_blocks = 1 8*130cbfc3SBram Moolenaar" let ps1_nofold_sig = 1 9*130cbfc3SBram Moolenaar" let ps1_nofold_region = 1 10*130cbfc3SBram Moolenaar 11*130cbfc3SBram Moolenaarif exists("b:current_syntax") 12*130cbfc3SBram Moolenaar finish 13*130cbfc3SBram Moolenaarendif 14*130cbfc3SBram Moolenaar 15*130cbfc3SBram Moolenaar" Operators contain dashes 16*130cbfc3SBram Moolenaarsetlocal iskeyword+=- 17*130cbfc3SBram Moolenaar 18*130cbfc3SBram Moolenaar" PowerShell doesn't care about case 19*130cbfc3SBram Moolenaarsyn case ignore 20*130cbfc3SBram Moolenaar 21*130cbfc3SBram Moolenaar" Sync-ing method 22*130cbfc3SBram Moolenaarsyn sync minlines=100 23*130cbfc3SBram Moolenaar 24*130cbfc3SBram Moolenaar" Certain tokens can't appear at the top level of the document 25*130cbfc3SBram Moolenaarsyn cluster ps1NotTop contains=@ps1Comment,ps1CDocParam,ps1FunctionDeclaration 26*130cbfc3SBram Moolenaar 27*130cbfc3SBram Moolenaar" Comments and special comment words 28*130cbfc3SBram Moolenaarsyn keyword ps1CommentTodo TODO FIXME XXX TBD HACK NOTE contained 29*130cbfc3SBram Moolenaarsyn match ps1CDocParam /.*/ contained 30*130cbfc3SBram Moolenaarsyn match ps1CommentDoc /^\s*\zs\.\w\+\>/ nextgroup=ps1CDocParam contained 31*130cbfc3SBram Moolenaarsyn match ps1CommentDoc /#\s*\zs\.\w\+\>/ nextgroup=ps1CDocParam contained 32*130cbfc3SBram Moolenaarsyn match ps1Comment /#.*/ contains=ps1CommentTodo,ps1CommentDoc,@Spell 33*130cbfc3SBram Moolenaarsyn region ps1Comment start="<#" end="#>" contains=ps1CommentTodo,ps1CommentDoc,@Spell 34*130cbfc3SBram Moolenaar 35*130cbfc3SBram Moolenaar" Language keywords and elements 36*130cbfc3SBram Moolenaarsyn keyword ps1Conditional if else elseif switch default 37*130cbfc3SBram Moolenaarsyn keyword ps1Repeat while for do until break continue foreach in 38*130cbfc3SBram Moolenaarsyn match ps1Repeat /\<foreach\>/ nextgroup=ps1Block skipwhite 39*130cbfc3SBram Moolenaarsyn match ps1Keyword /\<while\>/ nextgroup=ps1Block skipwhite 40*130cbfc3SBram Moolenaarsyn match ps1Keyword /\<where\>/ nextgroup=ps1Block skipwhite 41*130cbfc3SBram Moolenaar 42*130cbfc3SBram Moolenaarsyn keyword ps1Exception begin process end exit inlinescript parallel sequence 43*130cbfc3SBram Moolenaarsyn keyword ps1Keyword try catch finally throw 44*130cbfc3SBram Moolenaarsyn keyword ps1Keyword return filter in trap param data dynamicparam 45*130cbfc3SBram Moolenaarsyn keyword ps1Constant $true $false $null 46*130cbfc3SBram Moolenaarsyn match ps1Constant +\$?+ 47*130cbfc3SBram Moolenaarsyn match ps1Constant +\$_+ 48*130cbfc3SBram Moolenaarsyn match ps1Constant +\$\$+ 49*130cbfc3SBram Moolenaarsyn match ps1Constant +\$^+ 50*130cbfc3SBram Moolenaar 51*130cbfc3SBram Moolenaar" Keywords reserved for future use 52*130cbfc3SBram Moolenaarsyn keyword ps1Keyword class define from using var 53*130cbfc3SBram Moolenaar 54*130cbfc3SBram Moolenaar" Function declarations 55*130cbfc3SBram Moolenaarsyn keyword ps1Keyword function nextgroup=ps1Function skipwhite 56*130cbfc3SBram Moolenaarsyn keyword ps1Keyword filter nextgroup=ps1Function skipwhite 57*130cbfc3SBram Moolenaarsyn keyword ps1Keyword workflow nextgroup=ps1Function skipwhite 58*130cbfc3SBram Moolenaarsyn keyword ps1Keyword configuration nextgroup=ps1Function skipwhite 59*130cbfc3SBram Moolenaarsyn keyword ps1Keyword class nextgroup=ps1Function skipwhite 60*130cbfc3SBram Moolenaarsyn keyword ps1Keyword enum nextgroup=ps1Function skipwhite 61*130cbfc3SBram Moolenaar 62*130cbfc3SBram Moolenaar" Function declarations and invocations 63*130cbfc3SBram Moolenaarsyn match ps1Cmdlet /\v(add|clear|close|copy|enter|exit|find|format|get|hide|join|lock|move|new|open|optimize|pop|push|redo|remove|rename|reset|search|select|Set|show|skip|split|step|switch|undo|unlock|watch)(-\w+)+/ contained 64*130cbfc3SBram Moolenaarsyn match ps1Cmdlet /\v(connect|disconnect|read|receive|send|write)(-\w+)+/ contained 65*130cbfc3SBram Moolenaarsyn match ps1Cmdlet /\v(backup|checkpoint|compare|compress|convert|convertfrom|convertto|dismount|edit|expand|export|group|import|initialize|limit|merge|mount|out|publish|restore|save|sync|unpublish|update)(-\w+)+/ contained 66*130cbfc3SBram Moolenaarsyn match ps1Cmdlet /\v(debug|measure|ping|repair|resolve|test|trace)(-\w+)+/ contained 67*130cbfc3SBram Moolenaarsyn match ps1Cmdlet /\v(approve|assert|build|complete|confirm|deny|deploy|disable|enable|install|invoke|register|request|restart|resume|start|stop|submit|suspend|uninstall|unregister|wait)(-\w+)+/ contained 68*130cbfc3SBram Moolenaarsyn match ps1Cmdlet /\v(block|grant|protect|revoke|unblock|unprotect)(-\w+)+/ contained 69*130cbfc3SBram Moolenaarsyn match ps1Cmdlet /\v(use)(-\w+)+/ contained 70*130cbfc3SBram Moolenaar 71*130cbfc3SBram Moolenaar" Other functions 72*130cbfc3SBram Moolenaarsyn match ps1Function /\w\+\(-\w\+\)\+/ contains=ps1Cmdlet 73*130cbfc3SBram Moolenaar 74*130cbfc3SBram Moolenaar" Type declarations 75*130cbfc3SBram Moolenaarsyn match ps1Type /\[[a-z_][a-z0-9_.,\[\]]\+\]/ 76*130cbfc3SBram Moolenaar 77*130cbfc3SBram Moolenaar" Variable references 78*130cbfc3SBram Moolenaarsyn match ps1ScopeModifier /\(global:\|local:\|private:\|script:\)/ contained 79*130cbfc3SBram Moolenaarsyn match ps1Variable /\$\w\+\(:\w\+\)\?/ contains=ps1ScopeModifier 80*130cbfc3SBram Moolenaarsyn match ps1Variable /\${\w\+\(:\?[[:alnum:]_()]\+\)\?}/ contains=ps1ScopeModifier 81*130cbfc3SBram Moolenaar 82*130cbfc3SBram Moolenaar" Operators 83*130cbfc3SBram Moolenaarsyn keyword ps1Operator -eq -ne -ge -gt -lt -le -like -notlike -match -notmatch -replace -split -contains -notcontains 84*130cbfc3SBram Moolenaarsyn keyword ps1Operator -ieq -ine -ige -igt -ile -ilt -ilike -inotlike -imatch -inotmatch -ireplace -isplit -icontains -inotcontains 85*130cbfc3SBram Moolenaarsyn keyword ps1Operator -ceq -cne -cge -cgt -clt -cle -clike -cnotlike -cmatch -cnotmatch -creplace -csplit -ccontains -cnotcontains 86*130cbfc3SBram Moolenaarsyn keyword ps1Operator -in -notin 87*130cbfc3SBram Moolenaarsyn keyword ps1Operator -is -isnot -as -join 88*130cbfc3SBram Moolenaarsyn keyword ps1Operator -and -or -not -xor -band -bor -bnot -bxor 89*130cbfc3SBram Moolenaarsyn keyword ps1Operator -f 90*130cbfc3SBram Moolenaarsyn match ps1Operator /!/ 91*130cbfc3SBram Moolenaarsyn match ps1Operator /=/ 92*130cbfc3SBram Moolenaarsyn match ps1Operator /+=/ 93*130cbfc3SBram Moolenaarsyn match ps1Operator /-=/ 94*130cbfc3SBram Moolenaarsyn match ps1Operator /\*=/ 95*130cbfc3SBram Moolenaarsyn match ps1Operator /\/=/ 96*130cbfc3SBram Moolenaarsyn match ps1Operator /%=/ 97*130cbfc3SBram Moolenaarsyn match ps1Operator /+/ 98*130cbfc3SBram Moolenaarsyn match ps1Operator /-\(\s\|\d\|\.\|\$\|(\)\@=/ 99*130cbfc3SBram Moolenaarsyn match ps1Operator /\*/ 100*130cbfc3SBram Moolenaarsyn match ps1Operator /\// 101*130cbfc3SBram Moolenaarsyn match ps1Operator /|/ 102*130cbfc3SBram Moolenaarsyn match ps1Operator /%/ 103*130cbfc3SBram Moolenaarsyn match ps1Operator /&/ 104*130cbfc3SBram Moolenaarsyn match ps1Operator /::/ 105*130cbfc3SBram Moolenaarsyn match ps1Operator /,/ 106*130cbfc3SBram Moolenaarsyn match ps1Operator /\(^\|\s\)\@<=\. \@=/ 107*130cbfc3SBram Moolenaar 108*130cbfc3SBram Moolenaar" Regular Strings 109*130cbfc3SBram Moolenaar" These aren't precisely correct and could use some work 110*130cbfc3SBram Moolenaarsyn region ps1String start=/"/ skip=/`"/ end=/"/ contains=@ps1StringSpecial,@Spell 111*130cbfc3SBram Moolenaarsyn region ps1String start=/'/ skip=/''/ end=/'/ 112*130cbfc3SBram Moolenaar 113*130cbfc3SBram Moolenaar" Here-Strings 114*130cbfc3SBram Moolenaarsyn region ps1String start=/@"$/ end=/^"@/ contains=@ps1StringSpecial,@Spell 115*130cbfc3SBram Moolenaarsyn region ps1String start=/@'$/ end=/^'@/ 116*130cbfc3SBram Moolenaar 117*130cbfc3SBram Moolenaar" Interpolation 118*130cbfc3SBram Moolenaarsyn match ps1Escape /`./ 119*130cbfc3SBram Moolenaarsyn region ps1Interpolation matchgroup=ps1InterpolationDelimiter start="$(" end=")" contained contains=ALLBUT,@ps1NotTop 120*130cbfc3SBram Moolenaarsyn region ps1NestedParentheses start="(" skip="\\\\\|\\)" matchgroup=ps1Interpolation end=")" transparent contained 121*130cbfc3SBram Moolenaarsyn cluster ps1StringSpecial contains=ps1Escape,ps1Interpolation,ps1Variable,ps1Boolean,ps1Constant,ps1BuiltIn,@Spell 122*130cbfc3SBram Moolenaar 123*130cbfc3SBram Moolenaar" Numbers 124*130cbfc3SBram Moolenaarsyn match ps1Number "\(\<\|-\)\@<=\(0[xX]\x\+\|\d\+\)\([KMGTP][B]\)\=\(\>\|-\)\@=" 125*130cbfc3SBram Moolenaarsyn match ps1Number "\(\(\<\|-\)\@<=\d\+\.\d*\|\.\d\+\)\([eE][-+]\=\d\+\)\=[dD]\=" 126*130cbfc3SBram Moolenaarsyn match ps1Number "\<\d\+[eE][-+]\=\d\+[dD]\=\>" 127*130cbfc3SBram Moolenaarsyn match ps1Number "\<\d\+\([eE][-+]\=\d\+\)\=[dD]\>" 128*130cbfc3SBram Moolenaar 129*130cbfc3SBram Moolenaar" Constants 130*130cbfc3SBram Moolenaarsyn match ps1Boolean "$\%(true\|false\)\>" 131*130cbfc3SBram Moolenaarsyn match ps1Constant /\$null\>/ 132*130cbfc3SBram Moolenaarsyn match ps1BuiltIn "$^\|$?\|$_\|$\$" 133*130cbfc3SBram Moolenaarsyn match ps1BuiltIn "$\%(args\|error\|foreach\|home\|input\)\>" 134*130cbfc3SBram Moolenaarsyn match ps1BuiltIn "$\%(match\(es\)\?\|myinvocation\|host\|lastexitcode\)\>" 135*130cbfc3SBram Moolenaarsyn match ps1BuiltIn "$\%(ofs\|shellid\|stacktrace\)\>" 136*130cbfc3SBram Moolenaar 137*130cbfc3SBram Moolenaar" Named Switch 138*130cbfc3SBram Moolenaarsyn match ps1Label /\s-\w\+/ 139*130cbfc3SBram Moolenaar 140*130cbfc3SBram Moolenaar" Folding blocks 141*130cbfc3SBram Moolenaarif !exists('g:ps1_nofold_blocks') 142*130cbfc3SBram Moolenaar syn region ps1Block start=/{/ end=/}/ transparent fold 143*130cbfc3SBram Moolenaarendif 144*130cbfc3SBram Moolenaar 145*130cbfc3SBram Moolenaarif !exists('g:ps1_nofold_region') 146*130cbfc3SBram Moolenaar syn region ps1Region start=/#region/ end=/#endregion/ transparent fold keepend extend 147*130cbfc3SBram Moolenaarendif 148*130cbfc3SBram Moolenaar 149*130cbfc3SBram Moolenaarif !exists('g:ps1_nofold_sig') 150*130cbfc3SBram Moolenaar syn region ps1Signature start=/# SIG # Begin signature block/ end=/# SIG # End signature block/ transparent fold 151*130cbfc3SBram Moolenaarendif 152*130cbfc3SBram Moolenaar 153*130cbfc3SBram Moolenaar" Setup default color highlighting 154*130cbfc3SBram Moolenaarhi def link ps1Number Number 155*130cbfc3SBram Moolenaarhi def link ps1Block Block 156*130cbfc3SBram Moolenaarhi def link ps1Region Region 157*130cbfc3SBram Moolenaarhi def link ps1Exception Exception 158*130cbfc3SBram Moolenaarhi def link ps1Constant Constant 159*130cbfc3SBram Moolenaarhi def link ps1String String 160*130cbfc3SBram Moolenaarhi def link ps1Escape SpecialChar 161*130cbfc3SBram Moolenaarhi def link ps1InterpolationDelimiter Delimiter 162*130cbfc3SBram Moolenaarhi def link ps1Conditional Conditional 163*130cbfc3SBram Moolenaarhi def link ps1Cmdlet Function 164*130cbfc3SBram Moolenaarhi def link ps1Function Identifier 165*130cbfc3SBram Moolenaarhi def link ps1Variable Identifier 166*130cbfc3SBram Moolenaarhi def link ps1Boolean Boolean 167*130cbfc3SBram Moolenaarhi def link ps1Constant Constant 168*130cbfc3SBram Moolenaarhi def link ps1BuiltIn StorageClass 169*130cbfc3SBram Moolenaarhi def link ps1Type Type 170*130cbfc3SBram Moolenaarhi def link ps1ScopeModifier StorageClass 171*130cbfc3SBram Moolenaarhi def link ps1Comment Comment 172*130cbfc3SBram Moolenaarhi def link ps1CommentTodo Todo 173*130cbfc3SBram Moolenaarhi def link ps1CommentDoc Tag 174*130cbfc3SBram Moolenaarhi def link ps1CDocParam Identifier 175*130cbfc3SBram Moolenaarhi def link ps1Operator Operator 176*130cbfc3SBram Moolenaarhi def link ps1Repeat Repeat 177*130cbfc3SBram Moolenaarhi def link ps1RepeatAndCmdlet Repeat 178*130cbfc3SBram Moolenaarhi def link ps1Keyword Keyword 179*130cbfc3SBram Moolenaarhi def link ps1KeywordAndCmdlet Keyword 180*130cbfc3SBram Moolenaarhi def link ps1Label Label 181*130cbfc3SBram Moolenaar 182*130cbfc3SBram Moolenaarlet b:current_syntax = "ps1" 183