p:: Visual Studio Code

https://code.visualstudio.com/docs/editor/userdefinedsnippets

Create your own snippets

  • Create *.code-snippets file in .vscode folder

Below is an example of a for loop snippet for JavaScript:

.vscode/javascript.code-snippets
{
  "For Loop": {
    "prefix": ["for", "for-const"],
    "body": ["for (const ${2:element} of ${1:array}) {", "\t$0", "}"],
    "description": "A for loop."
  }
}
  • prefix defines one or more trigger words that display the snippet in IntelliSense. Substring matching is performed on prefixes, so in this case, "fc" could match "for-const".
  • body is one or more lines of content, which will be joined as multiple lines upon insertion.

Additionally, the body of the example above has three placeholders (listed in order of traversal): ${1:array}, ${2:element}, and $0. You can quickly jump to the next placeholder with Tab, at which point you may edit the placeholder or jump again the next one. The string after the colon (if any) is the default text, for example element in ${2:element}. Placeholder traversal order is ascending by number, starting from one; $0 is an optional special case that always comes last, and exits snippet mode with the cursor at the specified position.