Mastering Vibe Coding with Cursor AI

Mastering Vibe Coding with Cursor AI

Why Cursor for Vibe Coding

Cursor : An AI-powered IDE based on VS Code that integrates autocomplete, chat, and multi-file editing capabilities using Claude, GPT-4, and other models.

Cursor wins on speed and familiarity. It’s VS Code with AI superpowers. For developers who live in their IDE, nothing else matches the flow.

Configuration for Power Users

.cursorrules File

Create .cursorrules in your project root:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# Project Context

This is a Next.js 14 SaaS application using TypeScript, Tailwind CSS,
and Supabase. Follow these patterns:

## Code Style
- Use functional components with hooks
- Prefer named exports over default exports
- Use TypeScript strict mode
- Use absolute imports (@/ prefix)

## Security Requirements
- All database queries must be parameterized
- Verify user ownership before data access
- Validate all inputs with Zod
- Never expose internal errors to clients

## Patterns to Follow
- Server Components by default
- Use 'use client' only when necessary
- API routes in app/api/ directory
- Types in types/ directory

## Patterns to Avoid
- Don't use any type
- Don't use inline styles
- Don't hardcode strings (use constants)
- Don't create circular dependencies

## Testing
- Unit tests with Vitest
- E2E tests with Playwright
- Test files next to source files (*.test.ts)

Cursor reads this file and applies it to all suggestions.

Settings Optimization

In Cursor settings (Cmd+,):

1
2
3
4
5
6
7
{
  "cursor.ai.model": "claude-3.5-sonnet",
  "cursor.ai.autocomplete.enabled": true,
  "cursor.ai.autocomplete.delay": 100,
  "cursor.ai.chat.defaultContext": "codebase",
  "cursor.ai.composer.autoApply": false
}

Key settings:

  • model: Claude 3.5 Sonnet for best code quality
  • autocomplete.delay: Lower = faster suggestions
  • defaultContext: “codebase” includes relevant files automatically
  • autoApply: false to review changes before applying

Custom Prompts

Add frequently used prompts to snippets:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
// .vscode/cursor.code-snippets
{
  "Security Review": {
    "prefix": "//secreview",
    "body": "Review this code for security vulnerabilities including IDOR, injection, auth bypass, and information disclosure."
  },
  "Add Tests": {
    "prefix": "//addtests",
    "body": "Add comprehensive unit tests for this file. Cover happy paths, error cases, and edge cases."
  }
}

Mastering Autocomplete

Let It Learn

Cursor learns from your codebase. The more consistent your patterns, the better suggestions become.

Improve autocomplete quality:

  1. Keep code consistent
  2. Use descriptive names
  3. Add TypeScript types
  4. Write a few examples of each pattern

Tab-Tab-Tab Flow

The fastest workflow:

  1. Start typing a function name
  2. Tab to accept suggestion
  3. Tab through arguments
  4. Tab to complete

Don’t fight the autocomplete. Accept what’s close and modify.

Rejecting Bad Suggestions

If autocomplete suggests something wrong:

  • Type one more character to narrow it
  • Press Escape to clear
  • Press Cmd+Z to undo accepted suggestion

Chat Mode (Cmd+L)

Quick Questions

1
What does the createSubscription function do?

Cursor explains code in context.

Code Generation

1
2
3
4
5
Create a React hook that:
- Fetches user preferences from /api/preferences
- Caches results with SWR
- Returns preferences, loading state, and error
- Exports as usePreferences

Debugging

1
2
3
4
5
This function returns undefined sometimes:

[select code]

When does it return undefined and how do I fix it?

Refactoring

1
2
3
4
Refactor this component to:
- Extract the form logic into a custom hook
- Add loading and error states
- Use react-hook-form for validation

Composer Mode (Cmd+I)

Composer handles multi-file changes. Use for larger operations.

Feature Implementation

1
2
3
4
5
6
Add a notifications system:
1. Create NotificationService in lib/notifications.ts
2. Add notification types in types/notification.ts
3. Create NotificationProvider context
4. Add NotificationBell component in header
5. Create API route for fetching notifications

Composer creates and modifies multiple files in one operation.

Refactoring Across Files

1
2
3
4
5
Rename User to Account across the codebase:
- types/user.ts -> types/account.ts
- Update all imports
- Rename UserService to AccountService
- Update database schema comments

Pattern Application

1
2
Apply the existing error handling pattern from lib/api-utils.ts
to all API routes in app/api/

Advanced Workflows

The Review-Apply Loop

For complex changes:

  1. Ask in Chat mode first
  2. Review the suggestion
  3. If good, ask to apply
  4. If needs changes, refine the request
  5. Apply only when confident

Context Building

Before big changes, build context:

1
2
3
4
5
6
Read and understand:
- app/api/users/route.ts
- lib/auth.ts
- types/user.ts

I need to add user deletion with cascade behavior.

Then ask for the implementation.

Incremental Complexity

Start simple, add complexity:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# First prompt
Create a basic UserList component that displays users in a table.

# After it works
Add pagination to the UserList. 10 items per page.

# After pagination works
Add sorting by clicking column headers.

# After sorting works
Add search filtering by name and email.

Security Review Mode

Before committing:

1
2
3
4
5
6
7
8
Review this diff for security issues:
[paste git diff or select changed code]

Look for:
- Auth bypass vulnerabilities
- Input validation gaps
- Information disclosure
- IDOR vulnerabilities

Common Patterns

Adding a New Feature

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
Add user profile editing:

Requirements:
- Page at /settings/profile
- Form for name, email, bio
- Profile picture upload to Supabase storage
- Server action for update
- Success/error toast notifications

Follow existing form patterns in app/settings/

Fixing Bugs

1
2
3
4
5
6
7
8
Bug: Users can see other users' private notes

Expected: /api/notes returns only current user's notes
Actual: Returns all notes in database

File: app/api/notes/route.ts

Fix this and add a test for the fix.

Adding Tests

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
Add tests for UserService in lib/services/user.ts

Cover:
- Creating a user
- Updating a user
- Deleting a user
- Finding by email
- Error cases (duplicate email, not found)

Use the existing test patterns from lib/services/auth.test.ts

FAQ

Cursor vs Claude Code - which is better?

Different tools for different tasks. Cursor for rapid iteration and autocomplete. Claude Code for complex reasoning and multi-step operations. Use both.

My autocomplete suggestions are bad. How do I improve them?

Add a detailed .cursorrules file. Keep code consistent. Use TypeScript with strict types. Remove old/dead code that might confuse the model.

Composer changes break things. What am I doing wrong?

Review changes before applying (disable autoApply). Make smaller requests. Build context by reading relevant files first.

How do I handle large files that exceed context?

Reference specific sections. “In the handleSubmit function around line 150, add validation.” Don’t try to process entire large files at once.

Conclusion

Key Takeaways

  • Configure .cursorrules with project patterns and security requirements
  • Use Claude 3.5 Sonnet for best code quality
  • Tab-Tab-Tab flow for maximum autocomplete speed
  • Chat mode for questions and small changes
  • Composer mode for multi-file operations
  • Build context before complex changes
  • Incremental complexity—start simple, add features
  • Security review before committing

AI Coding Security Insights.
Ship Vibe-Coded Apps Safely.

Effortlessly test and evaluate web application security using Vibe Eval agents.