I am trying to get comfortable with Visual Studio Code for working with PowerShell scripts. Admittedly I still revert back to the ISE to debug the code. Maybe Code will provide that integrated interface one day but we will see. Moving on, one thing I use a great deal of are snippets. Admittedly I was completely lost on how to implement snippets in this IDE, then I found a great article from Keith Hill. This post provides information as well as a great starter file.
Now I want to add my own Snippets. The process is easy enough and the JSON editing in Visual Studio Code is pretty slick. I then found myself struggling with how to create a snippet and using PowerShell syntax create a variable. It starts with a dollar sign, easy enough right? Not really. The dollar sign is part of the snippet language as well. Yes I read this doc but didn’t put one and one together I guess. After some trial and error I found that $$ would then create the PowerShell syntax I was looking to achieve.
https://gist.github.com/jkavanagh58/1e06ac75860340cb1c1399b7676f7ebb.js
So in a PowerShell script I start typing the prefix and Intellisense detects possible matches, one of them being my Snippet:
Then I click on the User Snippet reference and the result is…
Now I have to start converting my library of snippets and then play with the dollar sign operator of Visual Studio Code snippets.
One thought on “Visual Studio Code Snippets”