Posted in Powershell

Visual Studio Code Snippets

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

image

So in a PowerShell script I start typing the prefix and Intellisense detects possible matches, one of them being my Snippet:

image

Then I click on the User Snippet reference and the result is…

image

Now I have to start converting my library of snippets and then play with the dollar sign operator of Visual Studio Code snippets.

Author:

USMC, CVID, Technology, PowerShell... just general ramblings

One thought on “Visual Studio Code Snippets

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s