What are code snippets?
Custom code snippets are a useful VS Code tool for quickly inserting commonly used code patterns with fewer mistakes. This is especially useful when dealing with structured JSON files, e.g. field definitions.
You can define snippets once and use them across your workspace.
How to set up snippets
To get started in VS Code, open the command palette and search for:
> Snippets: Configure User Snippets
Then select the language you want to create snippets for (e.g. JSON, Python, JavaScript).
Example snippet
{
"Print to console": {
"prefix": "log",
"body": [
"console.log(‘$1');",
"$2"
],
"description": "Log output to console"
}
}
prefix- the text that triggers the snippet in autocompletebody- the code that gets inserted. Use$1,$2etc. for tab stopsdescription- shown in the autocomplete menu
For more information and syntax for defining user snippets go to the official documentation.