Vim Tips Wiki
Advertisement

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 vim.org).
  • This page may be out of date: check the script's vim.org page above, and its release notes.

Powershell 2.0 features not covered

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 202.81.18.30 08:29, September 17, 2010 (UTC)

Comment based help

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)

Comments

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.

Advertisement