#VisualStudioCode – Create and use Code Snippets in @code, and create custom snippets just for your workspace

Buy Me A Coffee

Hi !

Code Snippets are super useful, and create your custom Code Snippets is super easy in Visual Studio Code. The official Documentation (see references) explains how to create snippets, with the full details of the JSON file, sections, contents and more. However there are some extra tips on top of this information that are super useful.

Snippet Creator

This is an amazing Visual Studio Code Extension. Just search for [snippet creator] on the Extension and install the extension.

visual studio code snippet creator extension

Once the extension is installed, the way to use this is super simple.

  • Select some code
  • CTRL + SHIFT + P, and type [create snippet]
  • Follow the steps, define snippet prefix, and optionally description
  • That’s it!
visual studio code snippet creator add new snippet

I created a custom snippet with the prefix [cameraCalcFPS] and now the snippet is available for any python file !

visual studio code custom code snippet available

In order to check all the custom code snippets

  • CTRL + SHIFT + P
  • Type [configure user snippets]
  • Open the specific one, for this sample python.json

The code snippets file has all the custom created snippets

visual studio code open custom snippets for python

Workspace specific snippets

There is also another specific scenario which I found very interesting:

The need for specific snippets inside a workspace

In order to do this, just create a file [mysnippets.code-snippets] and paste your own snippets here. This snippets will be only available for this workspace!

snippets for a workspace

Happy coding!

Greetings

El Bruno

References

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.