Skip to main content
⚡ OpenDevDocs
Developer ToolsVS Code
toolsvscodeGuideIntermediate

VS Code: Custom Code Snippets

Complete guide to authoring custom VS Code snippets for TypeScript, React, and Next.js, tab stops ($1, $2), placeholders, and variables.

Verified: 2026-09-30
Tested on:vscode 1.93.x
Platforms:
linuxmacoswindows
#vscode#snippets#productivity#json

Code Snippets are pre-configured code templates that expand when typing a prefix and pressing Tab, saving hours of repetitive boilerplate typing.


Creating Custom Snippets

  1. Open Command Palette: Cmd/Ctrl + Shift + P
  2. Type Preferences: Configure User Snippets
  3. Select the target language (e.g. typescriptreact.json for React/Next.js or global for all files).

Snippet Syntax & Anatomy

{
  "React Functional Component (TypeScript)": {
    "prefix": "rfc",
    "body": [
      "interface ${TM_FILENAME_BASE}Props {",
      "  $1",
      "}",
      "",
      "export function ${TM_FILENAME_BASE}({ $2 }: ${TM_FILENAME_BASE}Props) {",
      "  return (",
      "    <div className=\"$3\">",
      "      $0",
      "    </div>",
      "  );",
      "}"
    ],
    "description": "Creates a modern TypeScript React Functional Component using file basename"
  }
}

Tab Stops, Placeholders & Built-in Variables

SyntaxDescriptionExample
$1, $2, $3Tab Stops: Pressing Tab jumps cursor forward in sequence$1 (first stop), $2 (second stop)
${1:defaultVal}Placeholder: Default text selected on tab stop${1:isActive}
`${1one,two,three}`
$0Final Cursor Position: Where cursor rests when done editing snippet$0
$TM_FILENAME_BASEFile name without extensionIn UserCard.tsx, expands to UserCard
$CURRENT_YEAR4-digit current year2026
$CLIPBOARDCurrent clipboard text contents${CLIPBOARD}

Next.js Server Action Snippet Example

{
  "Next.js Server Action": {
    "prefix": "saction",
    "body": [
      "\"use server\";",
      "",
      "import { z } from \"zod\";",
      "",
      "export async function ${1:actionName}(formData: FormData) {",
      "  $0",
      "}"
    ],
    "description": "Next.js Server Action template"
  }
}

On this page