xxxxxxxxxx
/*To create or edit your own snippets, select User Snippets
under File > Preferences > User Snippets (Code > Preferences on macOS),
and then select the language for which the snippets should appear*/
// Snippets are written in JSON Example:
{
"Your Snippet Name": {
"prefix": "ysn",
"body": [
"//Here you type all the code that should appear",
"//Separating each line",
"//Remember to add tabs with \t"
]
}
}
xxxxxxxxxx
Hit > shift + command + p and type snippets
Select Preferences: Open User Snippets
Choose the language type for which you want to add the custom snippet
vscode has comments to explain on how to add a snippet, as described on :> vsdoc
Lets say, we want to open custom snippets for the language GO. Then we can do:
Hit > command + p
Type: go.json + enter And you land on the custom snippet page
Snippets are defined in a JSON format and stored in a per user (languageId).json file. For example, Markdown snippets go in a markdown.json file.
Update new tools:
Snippet generator site: https://snippet-generator.app/
xxxxxxxxxx
Visual Studio Code, customize / make your own code snippets
For tutorial: https://code.visualstudio.com/docs/editor/userdefinedsnippets#_create-your-own-snippets
Premade snippets for Python: https://github.com/microsoft/vscode-python/blob/2020.12.424452561/snippets/python.json
xxxxxxxxxx
{
// Place your global snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is
// used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders.
// Placeholders with the same ids are connected.
// Example:
"Styles.ts Boiler": {
"scope": "javascript,typescript",
"prefix": "sty",
"body": [
"import { makeStyles } from 'tss-react/mui'",
"const useStyles = makeStyles()(() => ({",
"root: {}",
"}))",
"export default useStyles"
],
"description": "styles.ts boilerplate code"
}
}
xxxxxxxxxx
// in file 'Code/User/snippets/javascript.json' for only JS files
{
"For Loop": {
"prefix": ["for", "for-const"],
"body": ["for (const ${2:element} of ${1:array}) {", "\t$0", "}"],
"description": "A for loop."
}
}
// in file 'Code/User/snippets/fileName.code-snippets' for Global Snippets
{
"For Loop": {
"scope": "javascript,typescript,php,html",
"prefix": ["for", "for-const"],
"body": ["for (const ${2:element} of ${1:array}) {", "\t$0", "}"],
"description": "A for loop."
}
}
xxxxxxxxxx
{
"Include General Namespace": {
"prefix": "Namesp",
"body": [
"using System;",
"using System.Collections.Generic;",
"using System.Linq;",
"using System.Text;"
],
"description": "For Including General Namespace"
}
}