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.
This is an amazing Visual Studio Code Extension. Just search for [snippet creator] on the Extension and install the 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!
I created a custom snippet with the prefix [cameraCalcFPS] and now the snippet is available for any python file !
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
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!
More posts in my blog ElBruno.com.