Cursor - Introduction
Overview
Estimated time: 35โ45 minutes
Cursor is an AI-first code editor built on VS Code that integrates advanced AI capabilities directly into the development experience. This tutorial covers installation, key features, and effective workflows.
Learning Objectives
- Install and configure Cursor for optimal AI-assisted development
- Master the AI chat interface and codebase conversation features
- Use Composer for multi-file editing and complex refactoring
- Apply best practices for AI-first development workflows
Prerequisites
- AI Agents - Introduction
- Basic familiarity with VS Code or similar editors
- Understanding of software development workflows
What is Cursor?
Cursor is a code editor designed from the ground up for AI-assisted development. Built on VS Code, it adds powerful AI features while maintaining compatibility with VS Code extensions and settings.
Key Differentiators:
- Codebase Chat: Converse with your entire project
- Composer: AI agent for multi-file editing
- Apply: Direct code suggestions with one-click application
- Privacy-first: Options for local models and data control
Installation & Setup
Download and Install
# Download from cursor.com
# Available for Windows, macOS, and Linux
# macOS
curl -L https://cursor.sh/download/mac -o cursor.dmg
open cursor.dmg
# Windows - Download installer from website
# Linux - Download AppImage or use package manager
First Launch Setup
1. Import VS Code settings (optional)
โ
Extensions
โ
Keybindings
โ
Settings
โ
Themes
2. Choose AI model
โข GPT-4 (recommended)
โข GPT-3.5-turbo (faster)
โข Claude-3
โข Local models (advanced)
3. Configure privacy settings
โข Data retention preferences
โข Model fine-tuning opt-out
โข Privacy mode options
Authentication
# Sign in options
1. GitHub account (recommended)
2. Google account
3. Email/password
4. Enterprise SSO (for teams)
# Subscription plans
- Free: 2000 completions/month
- Pro: $20/month - unlimited usage
- Business: $40/user/month - team features
Core Features
AI Chat Interface
The chat panel is accessible via Ctrl+L and provides several conversation modes:
Chat Modes:
๐จ๏ธ Normal Chat - General AI assistance
๐ Codebase Chat - Context-aware with full project
๐ฏ Composer - Multi-file editing agent
๐ง Apply - Direct code modifications
Codebase Chat Example
User: "How does user authentication work in this project?"
Cursor AI: "Looking at your codebase, I can see you're using JWT-based
authentication. Here's how it works:
1. **Login endpoint** (auth/login.js:15-32):
- Validates email/password against database
- Generates JWT token with user data
- Returns token and user info
2. **Middleware** (middleware/auth.js:8-25):
- Extracts token from Authorization header
- Verifies JWT signature and expiration
- Attaches user object to request
3. **Protected routes** use the authenticateToken middleware:
- /api/profile (routes/user.js:12)
- /api/posts (routes/posts.js:8)
Would you like me to explain any specific part or suggest improvements?"
Composer for Multi-File Editing
Composer is Cursor's most powerful feature - an AI agent that can modify multiple files simultaneously:
Example Composer Request:
"Add user profile pictures to the app. I need:
1. Database migration to add avatar_url to users table
2. Upload endpoint in the API
3. Update the Profile component to show/edit avatar
4. Add image optimization and validation"
Composer Response:
๐ I'll help you add profile pictures. Here are the files I'll modify:
๐ migrations/add_avatar_to_users.sql
๐ routes/upload.js
๐ components/Profile.jsx
๐ utils/imageProcessor.js
๐ middleware/uploadMiddleware.js
[Shows preview of all changes]
โ
Apply all changes โ Reject ๐ Edit individual files
Key Keyboard Shortcuts
Core AI Features
- Ctrl + L - Open AI chat
- Ctrl + K - Inline edit
- Ctrl + I - Composer mode
- Tab - Accept AI suggestion
- Ctrl + Enter - Apply changes
Chat & Context
- Ctrl + Shift + L - Codebase chat
- @filename - Reference specific file
- @docs - Include documentation
- @web - Search web for context
- Esc - Clear/cancel operation
Navigation & Selection
- Ctrl + Click - Add to context
- Ctrl + A - Select all for context
- Alt + Click - Multi-cursor with AI
- Ctrl + D - Select similar with AI help
- F1 - Command palette
Advanced Features
- Ctrl + Shift + I - Privacy mode toggle
- Ctrl + / - AI-powered commenting
- Ctrl + Shift + R - Refactor with AI
- F2 - AI-assisted rename
- Ctrl + . - Quick fix with AI
Practical Workflows
New Feature Development
Workflow: Adding a "Comments" feature to a blog
1. ๐ฌ Codebase Chat: "I want to add comments to blog posts.
What's the best approach given my current architecture?"
2. ๐ฏ Composer: "Implement a complete comments system:
- Database schema for comments
- API endpoints (CRUD)
- React components for display/form
- Real-time updates with WebSocket"
3. ๐ง Apply: Review each file change individually
4. ๐งช Test: Ask AI to generate test cases
5. ๐ Document: Generate README updates
Bug Fixing
Workflow: Fixing a performance issue
1. ๐ Select slow code section
2. ๐ฌ Chat: "This function is slow with large datasets.
How can I optimize it?"
3. ๐ง Apply suggested optimizations
4. ๐งช Ask for performance tests
5. ๐ Request benchmarking code
Code Review & Refactoring
// Select problematic code
function processUsers(users) {
let result = [];
for (let i = 0; i < users.length; i++) {
if (users[i].active == true) {
if (users[i].role !== 'admin') {
result.push({
id: users[i].id,
name: users[i].name,
email: users[i].email
});
}
}
}
return result;
}
// Chat: "Refactor this function to be more functional and readable"
// AI suggests:
const processUsers = (users) =>
users
.filter(user => user.active && user.role !== 'admin')
.map(({ id, name, email }) => ({ id, name, email }));
Context Management
File References
Chat with specific files:
"@api/users.js @components/UserList.jsx
The UserList component isn't displaying data from the API correctly.
Can you identify the issue?"
Include documentation:
"@docs How do I implement pagination in this framework?"
Web search context:
"@web What are the latest React performance best practices?"
Project-Wide Context
Codebase questions:
โข "What dependencies does this project use?"
โข "Show me all the API endpoints"
โข "Where is error handling implemented?"
โข "What testing strategy is used?"
โข "How is authentication handled across components?"
Advanced Features
Custom Instructions
Set project-specific guidelines:
Code Style:
- Use TypeScript with strict mode
- Prefer functional components with hooks
- Use Tailwind CSS for styling
- Follow REST API conventions
Architecture:
- Keep components under 100 lines
- Separate business logic into custom hooks
- Use React Query for data fetching
- Implement proper error boundaries
Model Selection
Choose the right model for your task:
GPT-4:
โ
Complex reasoning
โ
Architecture decisions
โ
Code review
โ Slower response
GPT-3.5-Turbo:
โ
Fast responses
โ
Simple completions
โ
Routine tasks
โ Less sophisticated reasoning
Claude-3:
โ
Long context windows
โ
Document analysis
โ
Complex refactoring
โ Limited code generation
Privacy Controls
Privacy Options:
๐ Privacy Mode - No data sent to AI providers
๐ Local Models - Run AI on your machine
๐ Data Retention - Control how long chats are stored
๐ซ Opt-out - Exclude your code from model training
๐ SOC 2 Compliance - Enterprise security standards
Best Practices
Effective Prompting
- Be specific: "Refactor this React component to use hooks" vs "improve this code"
- Provide context: Include relevant files and explain the goal
- Ask for explanations: Understanding improves long-term skills
- Iterate: Build on previous responses for complex tasks
Code Quality
- Always review: AI suggestions before applying
- Test thoroughly: AI-generated code needs validation
- Maintain style: Ensure consistency with your codebase
- Understand logic: Don't apply code you don't comprehend
Team Collaboration
- Share settings: Export/import Cursor configurations
- Document AI usage: Note when AI assisted in commits
- Code review: Extra scrutiny for AI-generated code
- Train teammates: Share effective prompting patterns
Common Use Cases
Learning New Technologies
Chat: "I'm new to GraphQL. Can you:
1. Explain the key concepts
2. Show me how to set up a basic schema
3. Create a resolver example
4. Write a simple client query"
AI provides step-by-step learning with code examples
API Integration
Composer: "Integrate Stripe payments into this checkout flow:
- Add Stripe SDK to the project
- Create payment intent endpoint
- Build checkout form component
- Handle success/error states
- Add webhook for payment confirmation"
Modifies multiple files with complete integration
Testing & Documentation
// Select function to test
function calculateShipping(weight, distance, priority) {
// Complex shipping calculation logic
}
// Chat: "Generate comprehensive tests for this function"
// AI creates test cases covering edge cases, error conditions
// Also generates JSDoc documentation automatically
Common Issues & Solutions
Performance
- Slow responses: Switch to GPT-3.5-turbo
- Context limits: Break large files into smaller chunks
- Memory usage: Restart editor periodically
Accuracy
- Wrong suggestions: Provide more context
- Outdated info: Specify versions/frameworks
- Style inconsistency: Set custom instructions
Checks for Understanding
- What's the difference between regular chat and codebase chat in Cursor?
- How do you reference specific files in a Cursor conversation?
- What is Composer and when should you use it?
Show answers
- Codebase chat has full project context and can understand your entire codebase
- Use @filename.ext to reference specific files in your chat
- Composer is for multi-file editing tasks like adding features or large refactoring
Exercises
- Install Cursor and import your VS Code settings
- Use codebase chat to ask about an existing project's architecture
- Try Composer to add a simple feature across multiple files
- Practice using @ references to include specific context in conversations