Skip to content

Snippet Management

You are building a new React component and you type useState for the fifth time today. Tab completion fills in the hook, but you still have to manually add the TypeScript types, the initial value, and the pattern for handling loading and error states. Every component starts with the same 15-line boilerplate, and every time you write it slightly differently. Meanwhile, your teammate structures their components a different way entirely.

Snippets solve the boilerplate problem, but traditional VS Code snippets are static templates that do not adapt to your project’s patterns. When you combine snippets with Cursor’s AI, you get dynamic code generation that follows your conventions automatically.

  • A snippet strategy that combines VS Code snippets with Cursor rules for maximum speed
  • Copy-paste rules that turn common patterns into instant boilerplate
  • Techniques for generating and managing project-specific snippets
  • Workflow patterns for using snippets alongside AI-generated code

Layer 1: VS Code Snippets for Muscle Memory

Section titled “Layer 1: VS Code Snippets for Muscle Memory”

Use traditional VS Code snippets for patterns you type dozens of times per day. These are instant (no AI round-trip) and deterministic (same output every time):

{
"React Functional Component": {
"prefix": "rfc",
"scope": "typescriptreact",
"body": [
"interface ${1:Component}Props {",
" $2",
"}",
"",
"export function ${1:Component}({ $3 }: ${1:Component}Props) {",
" $0",
" return (",
" <div>",
" ",
" </div>",
" )",
"}"
]
}
}

Store project-specific snippets in .vscode/project.code-snippets and check them into version control.

Layer 2: Cursor Rules for Smart Boilerplate

Section titled “Layer 2: Cursor Rules for Smart Boilerplate”

For patterns that need to adapt to context (the right imports, the right types, the right error handling for this specific project), use Cursor rules instead of static snippets:

---
description: Generate boilerplate for a new API route handler
alwaysApply: false
---
When I ask you to create a new route handler, generate this structure:
1. Import the required middleware from @src/middleware/
2. Import the Zod schema from @src/schemas/
3. Import the service from @src/services/
4. Create the handler with proper TypeScript types
5. Add validation, authentication, error handling
6. Follow the exact pattern in @src/routes/users.ts
This rule generates context-aware boilerplate, not static templates.

Let Cursor analyze your codebase and generate snippets based on your actual patterns:

  1. Type the snippet prefix (rfc for a React component)
  2. Tab through the placeholders to set the component name and props
  3. Press Cmd+K to fill in the component body with AI: “fetch user notifications and display them in a list”
  4. Tab to accept the AI suggestion

This combines the speed of snippets (instant boilerplate) with the intelligence of AI (context-aware implementation).

When you need to create something that follows an existing pattern:

  1. Open the file you want to replicate
  2. Press Cmd+Shift+L to add it as context
  3. Open a new file
  4. Tell Agent: “Create a [new thing] following the exact pattern in the file I added as context”

This is effectively a “smart snippet” that adapts the template to your specific needs.

Snippets conflict with Tab completion. If a VS Code snippet prefix conflicts with Cursor’s Tab suggestions, the snippet takes priority. Choose unique prefixes that do not overlap with common code tokens.

AI-generated boilerplate drifts from snippets. When your rules and snippets describe different patterns, developers get inconsistent output. Keep them aligned: when you update a snippet, update the corresponding rule.

Too many snippets slow down autocomplete. If you have 100+ snippets, the autocomplete dropdown becomes noisy. Prefix snippets by category (api-, comp-, test-) so you can type the category to filter.