Vim Tips Wiki
(standard format)
 
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{ScriptComments|1327|Windows PowerShell syntax file: default syntax coloring for Windows PowerShell}}
+
{{ScriptComments|Windows PowerShell syntax file: default syntax coloring for Windows PowerShell}}
   
 
==Powershell 2.0 features not covered==
 
==Powershell 2.0 features not covered==
Line 9: Line 9:
 
</pre>
 
</pre>
   
Then removing <tt>trap</tt> and <tt>throw</tt> from line 35 and adding these two lines in the appropriate places (lines 36 and 100 respectively) to handle exception keywords
+
Then removing <code>trap</code> and <code>throw</code> from line 35 and adding these two lines in the appropriate places (lines 36 and 100 respectively) to handle exception keywords
 
<pre>
 
<pre>
 
syn keyword ps1Exception trap throw try catch finally
 
syn keyword ps1Exception trap throw try catch finally
Line 15: Line 15:
 
</pre>
 
</pre>
 
dutchie [[Special:Contributions/202.81.18.30|202.81.18.30]] 08:29, September 17, 2010 (UTC)
 
dutchie [[Special:Contributions/202.81.18.30|202.81.18.30]] 08:29, September 17, 2010 (UTC)
  +
  +
===Comment based help===
  +
I use the following for comment based help.
  +
<pre>
  +
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
  +
</pre>
  +
  +
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 <pre>syn region ps1MultiLineComment start=/<#/ end=/#>/ fold contains=ps1CommentHelp,ps1CommentTodo</pre>
  +
  +
chilversc 11:24, June 09, 2011 (BST)
   
 
==Comments==
 
==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.
  +
  +
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.

Latest revision as of 19:15, 28 September 2012

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.

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.