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:

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. Render a loading skeleton while fetching, an error state with a retry button on failure, and an empty state when there are no notifications.”
  4. Tab to accept the AI suggestion

This is exactly the boilerplate from the opening scenario: the rfc snippet drops in the typed shell instantly, and the Cmd+K instruction makes Cursor fill the loading, error, and empty states the same way every time — so the three states stop being something each teammate writes slightly differently. It 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.

Rules go stale when the reference file moves. A rule that points at @src/components/UserProfile.tsx silently degrades the day someone renames or relocates that file — the agent keeps generating against a path that no longer resolves. Anchor rules to a canonical example you intend to keep, and update the @-path whenever you refactor it. When in doubt, ask Cursor to “list every .cursor/rules/*.mdc file that references a path that no longer exists in the repo” so you can fix them in one pass.