How to create per workspace snippets in VSCode?

Per this solution on vscode issues in github, you just need to:

  1. Create a file with .code-snippets extension (e.g. typescript.code-snippets), and
  2. Add the content you have in mind to that file. e.g. a simple fog snippet for console.log:
{
    "Print to console": {
        "prefix": "fog",
        "body": [
            "console.log('$1');",
            "$2"
        ],
        "description": "Log output to console"
    }
}
  1. 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.


Go to File -> Prefrences -> User snippets. Choose New Snippets for ${project name}. Give the snippet file a name of your choice. Read the comment in the file just created, and copy the example to create the first snippet.


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.

Project Level Snippet

Snippets also now support multiple prefixes. If you cannot decide if your copyright header snippet should be prefixed as header, stub, or copyright, you can have them all. Use a string array as the prefix property.

{
  "prefix": ["header", "stub", "copyright"],
  "body": "Copyright. Foo Corp 2028",
  "description": "Adds copyright...",
  "scope": "javascript,typescript"
}