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
- Open Command Palette: Cmd/Ctrl + Shift + P
- Type
Preferences: Configure User Snippets - Select the target language (e.g.
typescriptreact.jsonfor React/Next.js orglobalfor 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
| Syntax | Description | Example |
|---|---|---|
$1, $2, $3 | Tab 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} |
| `${1 | one,two,three | }` |
$0 | Final Cursor Position: Where cursor rests when done editing snippet | $0 |
$TM_FILENAME_BASE | File name without extension | In UserCard.tsx, expands to UserCard |
$CURRENT_YEAR | 4-digit current year | 2026 |
$CLIPBOARD | Current 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"
}
}Related Guides
VS Code: Profiles & Workspace Customization
Complete guide to creating and switching VS Code profiles for different tech stacks (Frontend, Python, DevOps, Java), exporting profiles, and syncing.
VS Code: Interactive Debugging & launch.json
Complete guide to VS Code debugging, breakpoints, conditional breakpoints, logpoints, watch variables, call stack inspection, and launch.json configurations.