Life's random bits By b1thunt3r (aka Ishan Jain)…
Custom Snippets in Visual Studio Code

Custom Snippets in Visual Studio Code

Ishan jain
Create simple templates in Visual Studio Code

To speed up development in Visual Studio Code, we can leverage snippets.

  1. 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.

  2. Create a new javascript file in your project.

  3. In the .js file write for and press CTRL+SPACE and select your custom snippet.

Resources