Đọc bằng ngôn ngữ:
Mục lục
· ngaicode · Hướng Dẫn · 9 min read

Hướng Dẫn Cursor 2026: Cách Sử Dụng Agent Mode và Composer

Hướng dẫn chi tiết cách sử dụng Cursor IDE 2026 - setup, Agent Mode, Composer, MCP, shortcuts, tips & tricks. Tutorial từ cơ bản đến nâng cao cho developer Việt Nam.

Hướng Dẫn Cursor 2026: Cách Sử Dụng Agent Mode và Composer

TL;DR: Cursor là AI IDE mạnh nhất 2026 với Agent Mode (AI tự động làm multi-step tasks), Composer (multi-file editing), và MCP (kết nối external tools). Bài hướng dẫn này sẽ dạy bạn: (1) Cài đặt và setup, (2) Sử dụng Agent Mode hiệu quả, (3) Composer workflow, (4) MCP configuration, (5) Shortcuts và tips. Đọc xong bạn sẽ biết cách maximize productivity với Cursor.

Liên kết quan trọng:


Phần 1: Cài Đặt và Setup Cursor

Bước 1: Download và Cài Đặt

  1. Download Cursor

    • Truy cập: cursor.com
    • Chọn phiên bản cho OS của bạn (Windows/Mac/Linux)
    • File size: ~150MB
  2. Cài Đặt

    # macOS
    Open Cursor.dmg → Drag to Applications
    
    # Windows
    Run CursorSetup.exe → Follow installer
    
    # Linux
    chmod +x cursor.AppImage
    ./cursor.AppImage
  3. Khởi Chạy Lần Đầu

    • Mở Cursor
    • Sign in với Google/GitHub (hoặc tạo account)
    • Chọn theme (Dark/Light)
    • Import settings từ VS Code (nếu có)

Bước 2: API Key Configuration

Cursor cần API keys để truy cập AI models:

Option A: Sử Dụng Cursor Built-in (Khuyến nghị cho beginners)

  1. Mở Settings (Cmd+, hoặc Ctrl+,)
  2. Vào Features → Models
  3. Chọn tier:
    • Free: 2 tuần trial
    • Pro: $20/tháng (500 fast requests)
  4. Enter payment method

Option B: Custom API Keys (Cho advanced users)

// Settings → Features → Models → Override API Keys
{
  "openai": {
    "apiKey": "sk-...",
    "baseURL": "https://api.openai.com/v1"
  },
  "anthropic": {
    "apiKey": "sk-ant-...",
    "baseURL": "https://api.anthropic.com"
  }
}

Tips: Mua API keys qua reseller rẻ hơn 50-80% so với official.

Bước 3: Essential Settings

Keyboard Shortcuts:

Cmd+K (Ctrl+K)    → Inline editing
Cmd+L (Ctrl+L)    → Chat
Cmd+I (Ctrl+I)    → Composer/Agent Mode
Tab               → Accept suggestion
Cmd+Shift+P       → Command Palette

Model Selection:

  1. Mở Settings → Models
  2. Set default models:
    • Autocomplete: GPT-4o (nhanh)
    • Chat: Claude Sonnet 3.7 (reasoning tốt)
    • Agent: GPT-5.6 hoặc Claude Opus (mạnh nhất)

Privacy Mode (quan trọng):

Settings → Features → Privacy Mode → Enable

Khi bật: Code không được gửi ra external servers để train models.


Phần 2: Cursor Basics - 4 Chế Độ Làm Việc

1. Autocomplete (Tab)

Khi nào dùng: Viết code thông thường, AI gợi ý real-time

Cách dùng:

// Type: "function to validate email"
// Cursor tự động suggest:
function validateEmail(email) {
  const regex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
  return regex.test(email);
}
// Press Tab để accept

Tips:

  • Viết comment rõ ràng → AI suggest chính xác hơn
  • Press Esc để reject suggestion
  • Cmd+→ để accept từng word

2. Inline Edit (Cmd+K)

Khi nào dùng: Edit code trong file hiện tại

Cách dùng:

// Select đoạn code cần edit
// Press Cmd+K
// Type prompt: "add error handling"
// AI sẽ rewrite với error handling

// Before
function fetchData(url) {
  return fetch(url).then((res) => res.json());
}

// After Cmd+K "add error handling"
function fetchData(url) {
  return fetch(url)
    .then((res) => {
      if (!res.ok) throw new Error(`HTTP ${res.status}`);
      return res.json();
    })
    .catch((err) => {
      console.error('Fetch error:', err);
      throw err;
    });
}

3. Chat (Cmd+L)

Khi nào dùng: Hỏi đáp, giải thích code, brainstorm

Cách dùng:

Cmd+L → Opens chat panel

Example prompts:
- "Explain this function @file:utils.ts"
- "How do I optimize this query?"
- "Generate tests for this component"
- "What's the best way to handle auth in React?"

Chat Features:

  • @file - Reference specific file
  • @folder - Reference entire folder
  • @code - Reference selected code
  • @docs - Search documentation

4. Agent Mode / Composer (Cmd+I)

Khi nào dùng: Multi-file changes, features mới, refactoring lớn

Cách dùng (xem chi tiết phần 3)


Phần 3: Agent Mode - Tính Năng Mạnh Nhất

Agent Mode Là Gì?

Agent Mode = AI tự động thực hiện multi-step tasks:

  • Edit nhiều files
  • Run terminal commands
  • Create new files
  • Fix errors và retry

Kích Hoạt Agent Mode

Press Cmd+I → Type request → Choose "Agent Mode"

Example 1: Thêm Feature Mới

Prompt:

Using Agent Mode, implement user authentication:
1. Create auth service in src/services/auth.ts
2. Add login/logout endpoints
3. Create React login component
4. Add protected route wrapper
5. Update App.tsx routing
6. Write tests for auth service

Cursor sẽ:

  1. ✅ Create auth.ts với login/logout logic
  2. ✅ Create LoginForm.tsx component
  3. ✅ Create ProtectedRoute.tsx wrapper
  4. ✅ Update App.tsx với routes
  5. ✅ Create auth.test.ts
  6. ✅ Run tests và fix nếu fail

Example 2: Refactor Toàn Bộ Module

Prompt:

@Agent refactor authentication module:
- Move all auth logic from /middleware to /services/auth
- Update all imports in affected files
- Maintain same API interface
- Run tests after each change
- Don't break existing functionality

Example 3: Debug và Fix

Prompt:

@Agent this test is failing:
@file: src/components/UserList.test.tsx

Find the root cause and fix it.
Add regression test to prevent this in future.

Agent Mode Best Practices

✅ DO:

  • Scope rõ ràng (specific files/folders)
  • Provide context với @file, @folder
  • Break down thành sub-tasks
  • Let Agent run tests và fix errors

❌ DON’T:

  • Request quá broad (“refactor entire codebase”)
  • Không provide context
  • Interrupt giữa chừng
  • Request > 10 files cùng lúc

Phần 4: Composer - Multi-File Editing

Composer Là Gì?

Composer = Structured multi-file editing với preview và planning phase.

Composer vs Agent Mode

FeatureAgent ModeComposer
Auto-execute✅ Yes❌ No (preview first)
Multi-file✅ Yes✅ Yes
PlanningAutoManual approval
ControlLowHigh

Sử Dụng Composer

Step 1: Mở Composer

Cmd+I → Choose "Composer"

Step 2: Describe Changes

Create a new API endpoint for user profile:
@file: src/routes/api.ts (add route)
@file: src/controllers/user.ts (add controller)
@file: src/services/user.ts (add service logic)

Step 3: Review Plan Cursor shows:

Plan:
1. Update src/routes/api.ts
   - Add GET /api/user/:id route
2. Update src/controllers/user.ts
   - Add getUserProfile controller
3. Update src/services/user.ts
   - Add getUserById service

Step 4: Preview Changes Click vào từng file để xem diff

Step 5: Apply

  • Accept all: Apply toàn bộ
  • Accept selective: Chọn từng change
  • Reject: Cancel và refine prompt

Composer Use Cases

✅ Multi-file feature additions
✅ API endpoint creation
✅ Component refactoring
✅ Migration tasks (e.g., class → functional components)
✅ Consistent changes across files


Phần 5: MCP (Model Context Protocol)

MCP Là Gì?

MCP = Cho phép Cursor truy cập external tools và data:

  • GitHub (repos, PRs, issues)
  • Linear (tasks, projects)
  • Notion (docs, databases)
  • Figma (designs)
  • Databases (PostgreSQL, MongoDB)

Setup MCP

Step 1: Mở MCP Settings

Settings → Features → Model Context Protocol

Step 2: Add MCP Server

Example: GitHub Integration

{
  "mcpServers": {
    "github": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-github"],
      "env": {
        "GITHUB_TOKEN": "ghp_..."
      }
    }
  }
}

Example: PostgreSQL

{
  "mcpServers": {
    "postgres": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-postgres"],
      "env": {
        "DATABASE_URL": "postgresql://user:pass@localhost/db"
      }
    }
  }
}

Step 3: Restart Cursor

Sử Dụng MCP

Query GitHub:

@Agent using GitHub MCP:
1. Get all open issues with label "bug"
2. Create a summary document
3. Prioritize by severity

Query Database:

@Agent using Postgres MCP:
1. Analyze users table schema
2. Suggest indexes for slow queries
3. Generate migration script

Access Figma:

@Agent using Figma MCP:
1. Get design tokens from design file
2. Generate CSS variables
3. Create React theme object

Phần 6: Advanced Tips & Tricks

1. Context Management

Problem: Cursor loses context trong long sessions

Solution:

Use @file, @folder explicitly in every prompt:

Bad:  "Add validation"
Good: "Add validation to @file:src/utils/validation.ts"

2. Model Switching

Strategy: Dùng model phù hợp cho từng task

Autocomplete → GPT-4o (fast, cheap)
Chat/Explain → Claude Sonnet (detailed)
Agent Mode → GPT-5.6 hoặc Opus (powerful)

3. Quota Management

Problem: Pro tier chỉ có 500 fast requests/tháng

Solutions:

  • Use slow model cho non-urgent tasks
  • Pin specific models để tránh auto-switch
  • Batch requests thay vì nhiều small requests

4. Custom Rules

Cursor Rules = Persistent instructions cho AI

Create .cursorrules file ở project root:

# .cursorrules
- Always use TypeScript strict mode
- Follow Airbnb style guide
- Write tests for all new functions
- Use functional components in React
- Comments should be in Vietnamese
- Prefer async/await over .then()

5. Keyboard Shortcuts Pro Tips

Cmd+Shift+K → Delete line
Cmd+D       → Select next occurrence
Cmd+/       → Toggle comment
Cmd+P       → Quick file open
Cmd+Shift+P → Command palette
Opt+↑/↓     → Move line up/down
Opt+Shift+↑/↓ → Copy line up/down

6. Terminal Integration

Cursor có integrated terminal với AI assistance:

# In terminal, prefix với "?"
? install react query

# AI suggests:
npm install @tanstack/react-query

Phần 7: Common Issues & Solutions

Issue 1: “Quota Exceeded”

Symptom: “You’ve reached your fast request limit”

Solutions:

  1. Wait for reset (monthly)
  2. Use slow model temporarily
  3. Upgrade to Pro+ ($60 = 3x quota)
  4. Use custom API keys

Issue 2: Agent Mode Stuck

Symptom: Agent keeps retrying same failed step

Solutions:

  1. Press “Stop” button
  2. Review error message
  3. Refine prompt với specific instructions
  4. Break down into smaller tasks

Issue 3: Incorrect Code Generation

Symptom: AI generates code không match yêu cầu

Solutions:

  1. Provide more context (@file, @folder)
  2. Add examples in prompt
  3. Use .cursorrules cho coding standards
  4. Try different model (switch GPT ↔ Claude)

Issue 4: Slow Response

Symptom: AI takes 30+ seconds để respond

Possible causes:

  • Large context (nhiều files referenced)
  • Complex reasoning model (o1-preview)
  • API rate limiting

Solutions:

  • Reduce context size
  • Switch to faster model
  • Check network connection

Phần 8: Workflow Examples

Workflow 1: Daily Coding

Morning:
1. Open Cursor
2. Pull latest từ Git
3. Check Linear/GitHub issues
4. Use Agent Mode để create feature branch
5. Use Composer để implement feature
6. Use Chat để review code
7. Let Agent run tests
8. Commit và push

Cursor làm:
- Generate boilerplate
- Auto-complete code
- Suggest best practices
- Run tests tự động
- Format code

Workflow 2: Bug Fixing

1. Reproduce bug
2. Cmd+L: "Explain why this error occurs @file:..."
3. Cmd+I Agent Mode: "Fix this bug and add regression test"
4. Review changes
5. Run tests
6. Commit fix

Workflow 3: Code Review

1. Checkout PR branch
2. Cmd+L: "@folder:src review this PR for:
   - Security issues
   - Performance problems
   - Best practice violations
   - Missing tests"
3. AI generates review comments
4. Post to GitHub

FAQ - Câu Hỏi Thường Gặp

Q1: Cursor có miễn phí không?

Có - 2 tuần trial miễn phí. Sau đó $20/tháng cho Pro hoặc dùng custom API keys.

Q2: Cursor khác VS Code như thế nào?

Cursor là VS Code fork nên gần như giống hệt, nhưng có built-in AI features (Agent Mode, Composer, MCP).

Q3: Tôi có thể import VS Code extensions không?

Có - Hầu hết VS Code extensions hoạt động trong Cursor.

Q4: Agent Mode có thể làm hỏng code không?

Có thể - Luôn review changes trước khi accept. Sử dụng Git để rollback nếu cần.

Q5: Cursor có hoạt động offline không?

Không - Cursor cần internet để access AI models. Nhưng basic editor features work offline.

Q6: Tôi có thể dùng Cursor cho Vietnamese comments không?

Có - Cursor models (GPT, Claude) hiểu tiếng Việt tốt. Thêm vào .cursorrules:

- All comments should be in Vietnamese

Q7: Làm sao mua Cursor rẻ hơn $20/tháng?

Mua qua reseller authorized - giá từ $15/tháng, thanh toán USD qua PayPal.


Kết Luận: Maximize Cursor Productivity

Checklist Để Thành Thạo Cursor

Week 1: Basics

  • Setup và configure Cursor
  • Học shortcuts cơ bản
  • Practice Cmd+K inline editing
  • Use Chat (Cmd+L) cho Q&A

Week 2: Intermediate

  • Thử Agent Mode cho simple tasks
  • Practice Composer workflow
  • Setup MCP cho GitHub
  • Create .cursorrules file

Week 3-4: Advanced

  • Agent Mode cho complex refactoring
  • Multi-MCP workflows
  • Custom API keys setup
  • Advanced prompt engineering

Key Takeaways

  1. Agent Mode = Tính năng killer của Cursor
  2. Composer = Dùng khi cần control nhiều hơn
  3. MCP = Unlock external tool integration
  4. .cursorrules = Persistent coding standards
  5. Model selection = Match model với task type

Next Steps

  1. Mua Cursor Pro với giá ưu đãi - Từ $15/tháng
  2. Đọc so sánh Cursor vs Copilot - Chọn tool phù hợp
  3. Xem tất cả công cụ AI Coding - Compare options

Tài Liệu Tham Khảo

  • Cursor Official Documentation - cursor.com/docs
  • Model Context Protocol Spec - modelcontextprotocol.io
  • Cursor Community Forum - forum.cursor.com
  • Cursor Tips & Tricks - cursor.com/blog
  • AI Coding Best Practices 2026

Cập nhật: 2026-09-06 | Tác giả: ngaicode Team
Từ khóa: cursor tutorial vietnam, hướng dẫn cursor, cursor agent mode, cursor composer, mcp setup, cursor vietnam

Quay lại Blog

Bài viết liên quan

Xem tất cả »
Zalo / WhatsApp