DevTools Logo

VS Code Snippet Generator

VS Code Snippet Generator

Author snippet bodies with tab stops and placeholders, then copy valid JSON.

Runs in your browser
Try an example

Snippet body

Generated snippet

0 body lines · 4 issue(s)

No snippet body yet

Type code, mark tab stops or load an example.

Examples

React component

Input
export function ${1:Component}()
Output
"body": ["export function ${1:Component}()"]

Placeholders give the first tab stop a useful default name.

Debug log

Input
console.log('$TM_FILENAME_BASE:${1:label}', ${2:value})
Output
prefix: [log]

Variables keep the log label tied to the current file.

Numbering gap

Input
${3:third} and $5
Output
Warnings for missing stops 1, 2 and 4

Validation points out numbering that would feel broken when expanded.

About this tool

VS Code Snippet Generator authors snippet JSON without memorizing the snippet grammar. Write a body, select text to mark it as a tab stop, placeholder, choice or variable, and copy the finished JSON into a language snippets file or a global .code-snippets file.

The escape engine preserves real snippet syntax while escaping literal dollar signs, backslashes and braces. It emits the body as a line array, splits prefixes into a list, adds a scope field for global files and drops the trailing newline that VS Code does not want in a body array.

Validation runs on every change: the generated JSON is parsed back, names and prefixes are checked, and tab stops are inspected for gaps and duplicates. Duplicates are allowed — VS Code gives them shared focus — but numbering gaps are reported because expansion would skip a stop.

The Preview tab simulates expansion with placeholder text filled in and variables shown as named tokens. It is a best-effort approximation for reviewing a body, not a replacement for testing the snippet inside VS Code.

What this tool does not do

  • Nested placeholders and regex transforms are not simulated in the preview; only flat markers are interpreted.
  • Choice values and placeholder defaults are plain text, not computed expressions.
  • The tool emits one snippet entry at a time; merge entries manually into an existing snippets file.
  • JSON is validated structurally, not against your editor's installed extensions or language IDs.
  • All work happens locally; the snippet body is not uploaded or saved after the tab closes.

How to use this tool

  1. Write the code

    Type or paste the snippet body. Literal dollar signs and backslashes are escaped automatically.

  2. Fill in metadata

    Add a snippet name, one or more comma-separated prefixes and a description. Toggle global mode for a .code-snippets file and set its scope.

  3. Mark tab stops

    Select text in the body and choose Tab stop, Placeholder, Choice or Variable. Numbering continues from the highest existing stop.

  4. Check validation

    Read the strip above the output. Errors mean the entry is incomplete; warnings such as a numbering gap are worth fixing but do not block export.

  5. Copy the file

    Copy the JSON or download snippets.json (or snippets.code-snippets in global mode), then place it in your VS Code user snippets directory.

Use cases

Team snippet libraries

Author shared snippets with consistent naming and prefixes, then commit the JSON to your repository.

Personal shortcuts

Wrap boilerplate you type daily into a global .code-snippets file scoped to the languages you use.

Teaching snippet syntax

Show how markers expand by switching between JSON and the preview before trying the snippet in the editor.

Import-style authoring

Start from a code sample, mark the variable parts and end with a validated snippet entry.

Snippet syntax reference

MarkerMeaning
$1, $2Numbered tab stops in visit order
${1:name}Tab stop with a default value
${1|a,b|}Choice list shown in a picker
$TM_FILENAME_BASEBuilt-in variable
\$Literal dollar sign
\\Literal backslash

Bodies are emitted as string arrays with no trailing empty line; $0 marks the final cursor position when present.

Common mistakes

Mistake:Leaving dollar signs unescaped in literal text.

Fix:The generator escapes standalone $ characters; use snippet syntax only where you intend a tab stop or variable.

Mistake:Starting tab stops at $2.

Fix:VS Code visits $1 first. The validator warns about gaps so you can renumber before copying.

Mistake:Adding a trailing newline to the body.

Fix:Trailing empty lines are removed because VS Code's body array would otherwise insert an extra line.

Mistake:Expecting a global file to have a language scope automatically.

Fix:In global mode, enter languages in the Scope field; leaving it blank makes the snippet available everywhere.

Mistake:Treating the preview as the snippet engine.

Fix:The preview only fills placeholders with representative text; test expansion in VS Code for transforms and nested placeholders.

Frequently asked questions

How do tab stops and placeholders work?

$1 is the first stop, $2 the next, and $0 marks the final cursor. ${1:name} fills the first stop with a default value, while ${1|a,b|} offers a choice picker. Select text in the body and use the marker buttons to insert the right syntax; numbering continues from the highest stop already present.

What happens to literal dollar signs and backslashes?

Standalone dollar signs become \$ and backslashes become \\ in the generated JSON body so VS Code treats them as literal characters. Recognized snippet syntax — numbered stops, placeholders, choices and variables — is preserved unchanged.

What is the difference between a language file and a .code-snippets file?

A language file (for example javascript.json) applies only to that language and has no scope field. Toggle global mode to export a .code-snippets file; you can then enter one or more comma-separated language IDs in the Scope field to control where the snippet appears.

Why does the validator warn about tab-stop gaps?

VS Code starts at $1 and moves upward. If your markers are $3 and $5, expansion skips stops and feels broken. Duplicate numbers are allowed and share focus across several positions, so they are reported as an informational warning rather than an error.

Which variables can I insert?

Common VS Code variables such as TM_FILENAME, TM_FILENAME_BASE, TM_DIRECTORY, TM_FILEPATH, TM_SELECTED_TEXT, CLIPBOARD, CURRENT_YEAR, CURRENT_DATE and WORKSPACE_NAME are available in the variable picker.

Does the preview expand snippets exactly like VS Code?

No. It is a best-effort approximation: placeholders show their default text, choices show the first option and variables appear as named tokens. Nested placeholders, regex transforms and editor-specific behavior should be tested inside VS Code.

Can I manage several snippets at once?

The tool builds one validated entry at a time. Copy each entry into your snippets JSON object, separating entries with commas; the output is formatted so it drops cleanly into an existing file.

Is my code uploaded?

No. Escaping, validation, JSON emission and preview all run in your browser tab. Nothing is sent to a server and there is no account or persistence layer.

References & standards