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

Prerequisites

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

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

  1. What's the difference between regular chat and codebase chat in Cursor?
  2. How do you reference specific files in a Cursor conversation?
  3. What is Composer and when should you use it?
Show answers
  1. Codebase chat has full project context and can understand your entire codebase
  2. Use @filename.ext to reference specific files in your chat
  3. Composer is for multi-file editing tasks like adding features or large refactoring

Exercises

  1. Install Cursor and import your VS Code settings
  2. Use codebase chat to ask about an existing project's architecture
  3. Try Composer to add a simple feature across multiple files
  4. Practice using @ references to include specific context in conversations