Custom Snippets in Visual Studio Code
Create simple templates in Visual Studio Code
To speed up development in Visual Studio Code, we can leverage snippets.
Create a new
*.code-snippet
file under.vscode
directory. For example we can create a.vscode/js-for.code-snippet
file. Paste the following in the file:// in file '.vscode/js-for/javascript.json' { "For Loop": { "scope": "javascript", "prefix": ["for", "for-const"], "body": ["for (const ${2:element} of ${1:array}) {", "\t$0", "}"], "description": "A for loop." } }
Note: This will create per-project snippets.
Create a new javascript file in your project.
In the
.js
file writefor
and pressCTRL+SPACE
and select your custom snippet.