Vim Tips Wiki


1,625pages on
this wiki
Add New Page

Use this page to discuss script 1327 Windows PowerShell syntax file: default syntax coloring for Windows PowerShell

  • Add constructive comments, bug reports, or discuss improvements (see the guideline).
  • Do not document the script here (the author should do that on
  • This page may be out of date: check the script's page above, and its release notes.

Powershell 2.0 features not coveredEdit

Version 2.7 of the Powershell syntax file (ps1.vim) does not cater for block comments (<# ... #>) and doesn't recognise the new Powershell 2.0 exception handling keywords (try, catch, finally). There are probably other Powershell 2.0 changes that are not covered, but these are all I have noticed so far.

I recommend adding the following to handle the comments:

syn region ps1Comment start=/<#/ end=/#>/ contains=ps1CommentTodo

Then removing trap and throw from line 35 and adding these two lines in the appropriate places (lines 36 and 100 respectively) to handle exception keywords

syn keyword ps1Exception trap throw try catch finally
HiLink ps1Exception Exception

dutchie 08:29, September 17, 2010 (UTC)

Comment based helpEdit

I use the following for comment based help.

syn match ps1CommentHelp /\.\(synopsis\|description\|parameter\|example\|inputs\)/ contained display
syn match ps1CommentHelp /\.\(outputs\|notes\|link\|component\|role\|functionality\)/ contained display
syn match ps1CommentHelp /\.\(forwardhelptargetname\|forwardhelpcategory\)/ contained display
syn match ps1CommentHelp /\.\(remotehelprunspace\|externalhelp\)/ contained display
syn region ps1MultiLineComment start=/<#/ end=/#>/ fold contains=ps1CommentHelp

HiLink ps1MultiLineComment Comment
HiLink ps1CommentHelp SpecialComment
The HiLink commands need to go at the bottom with the other HiLink commands. My personal preference is that multi-line comments should not contain TODOs so I've left them out. If you want TODOs in multi-line comments change ps1MultiLineComment to
syn region ps1MultiLineComment start=/<#/ end=/#>/ fold contains=ps1CommentHelp,ps1CommentTodo

chilversc 11:24, June 09, 2011 (BST)


Nice job. I've been using zsh/z-shell highlighting on posh for a bit over a year. It'll be good to have something that knows about backslashes. If I find any problems, I'll either submit a fix of give a shout. Thanks for the eye-candy.

Just a note to *nix users who want to do PowerShell development on *nix machines - do a dos2unix convert on the files prior to loading them into their respective directories. Works brilliantly once you do.

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.