How to create per workspace snippets in VSCode?
Project Level Snippets were added in the September 2018 Release of VSCode (version 1.28):
Snippets can now be scoped to a project and shared with your team. Use the Preferences: Configure User Snippets command or create
*.code-snippets
file in the.vscode
folder.Project snippets work just like other snippets, they show up in IntelliSense and in the Insert Snippet action where they now have their own category.
Snippets also now support multiple prefixes. If you cannot decide if your copyright header snippet should be prefixed as
header
,stub
, orcopyright
, you can have them all. Use a string array as theprefix
property.
{ "prefix": ["header", "stub", "copyright"], "body": "Copyright. Foo Corp 2028", "description": "Adds copyright...", "scope": "javascript,typescript"}
Per this solution on vscode issues in github, you just need to:
- Create a file with
.code-snippets
extension (e.g.typescript.code-snippets
), and - Add the content you have in mind to that file. e.g. a simple
fog
snippet forconsole.log
:
{ "Print to console": { "prefix": "fog", "body": [ "console.log('$1');", "$2" ], "description": "Log output to console" }}
- Put that file in the
.vscode
folder of the workspace (but not inside subfolders of that).
It works like a charm on VS Code 1.36.1.
As far as I know this is simply not possible directly in VS Code. After having read the VS Code documentation: https://code.visualstudio.com/docs/editor/userdefinedsnippets <-- I find no mention of this being possible.
Have a nice day.