logo
🤖 AI 工具

Cursor

Cursor Cheat Sheet - 快速参考指南,收录常用语法、命令与实践。

📂 分类 · AI 工具🧭 Markdown 速查🏷️ 3 个标签
#ai#ide#coding
向下滚动查看内容
返回全部 Cheat Sheets

Overview

What is Cursor
  • AI-powered code editor based on VS Code
  • Built-in AI assistant (Claude/GPT-4)
  • Supports code completion, chat, editing
  • Understands entire codebase context
Core Features
FeatureDescription
TabSmart code completion
ChatAI conversation assistant
ComposerMulti-file editing
@ ReferencesReference files/code/docs

Keyboard Shortcuts

AI Features
ShortcutAction
Cmd/Ctrl + KInline edit (Cmd K)
Cmd/Ctrl + LOpen Chat panel
Cmd/Ctrl + IOpen Composer
Cmd/Ctrl + Shift + IComposer (fullscreen)
TabAccept AI completion
EscCancel AI completion
Cmd/Ctrl + →Accept partial (word by word)
Editing
ShortcutAction
Cmd/Ctrl + Shift + KDelete current line
Cmd/Ctrl + EnterInsert line below
Cmd/Ctrl + Shift + EnterInsert line above
Alt + ↑/↓Move line
Alt + Shift + ↑/↓Copy line
Navigation
ShortcutAction
Cmd/Ctrl + PQuick open file
Cmd/Ctrl + Shift + PCommand palette
Cmd/Ctrl + GGo to line
Cmd/Ctrl + Shift + OGo to symbol
F12Go to definition
Shift + F12Find references
Multi-Cursor
ShortcutAction
Alt + ClickAdd cursor
Cmd/Ctrl + Alt + ↑/↓Add cursor above/below
Cmd/Ctrl + DSelect next match
Cmd/Ctrl + Shift + LSelect all matches
Search & Replace
ShortcutAction
Cmd/Ctrl + FFind in file
Cmd/Ctrl + HReplace in file
Cmd/Ctrl + Shift + FGlobal search
Cmd/Ctrl + Shift + HGlobal replace

Chat Feature

Opening Chat
CODE
滚动查看更多
Cmd/Ctrl + L

Or click the Chat icon in sidebar

@ References

File Reference

CODE
滚动查看更多
@filename.ts
Explain what this file does

Symbol Reference

CODE
滚动查看更多
@functionName
What's wrong with this function?

Folder Reference

CODE
滚动查看更多
@src/components
Analyze the code structure in this directory

Documentation Reference

CODE
滚动查看更多
@Docs
Look up React hooks documentation

Web Reference

CODE
滚动查看更多
@Web
Search for latest TypeScript 5.0 features

Git Reference

CODE
滚动查看更多
@Git
What changed in recent commits?

Codebase Reference

CODE
滚动查看更多
@Codebase
Where is user authentication implemented?
Common Chat Prompts

Code Explanation

CODE
滚动查看更多
Explain what this code does and why

Bug Finding

CODE
滚动查看更多
What bugs are in this code? How do I fix them?

Performance

CODE
滚动查看更多
How can I optimize this code for better performance?

Generate Tests

CODE
滚动查看更多
Write unit tests for this function

Add Comments

CODE
滚动查看更多
Add detailed comments to this code

Refactor

CODE
滚动查看更多
Refactor this to follow best practices
Chat Tips
  • Select code before opening Chat
  • Use @ references for context
  • Be specific in your questions
  • Use multi-turn conversation to clarify

Cmd K Inline Edit

Basic Usage
  1. Select code (or place cursor)
  2. Press Cmd/Ctrl + K
  3. Type your instruction
  4. Review diff and confirm
Common Instructions

Code Improvement

Refactor

CODE
滚动查看更多
Refactor using clearer variable names

Add Types

CODE
滚动查看更多
Add TypeScript type annotations

Error Handling

CODE
滚动查看更多
Add error handling and edge case checks

Optimize

CODE
滚动查看更多
Optimize for better performance

Simplify

CODE
滚动查看更多
Simplify this code

Code Transformation

Convert to Async

CODE
滚动查看更多
Convert to async/await syntax

Extract Function

CODE
滚动查看更多
Extract this logic into a separate function

Add Validation

CODE
滚动查看更多
Add input validation

Make Reusable

CODE
滚动查看更多
Make this more reusable and generic
Code Generation

Generate at empty line with Cmd/Ctrl + K:

React Component

CODE
滚动查看更多
Create a React component that displays a user profile card
with name, avatar, and bio

Utility Function

CODE
滚动查看更多
Write a function to validate email format
using regex

API Handler

CODE
滚动查看更多
Create an Express route handler for user registration
with validation and error handling

Algorithm

CODE
滚动查看更多
Implement binary search algorithm
with TypeScript generics
Cmd K Tips
  • More precise selection = more accurate changes
  • Be specific about your goal
  • Use Esc to cancel
  • Use Cmd/Ctrl + Z to undo

Composer Multi-File

Opening Composer
CODE
滚动查看更多
Cmd/Ctrl + I

Fullscreen mode:

CODE
滚动查看更多
Cmd/Ctrl + Shift + I
Use Cases
  • Creating features across multiple files
  • Refactoring code across files
  • Adding new API endpoints
  • Creating components with styles/tests
Example Prompts

Feature Creation

New Feature

CODE
滚动查看更多
Create a user authentication feature including:
- Login form component
- API route handler
- State management
- Form validation
- Error handling

CRUD Operations

CODE
滚动查看更多
Create a full CRUD API for blog posts:
- Model definition
- API routes (GET, POST, PUT, DELETE)
- Input validation
- Error responses

Code Organization

Component Split

CODE
滚动查看更多
Split this large component into smaller
sub-components, each in its own file:
- Header section
- Content area
- Footer section

Add Tests

CODE
滚动查看更多
Add comprehensive unit tests for all functions
in the src/utils directory using Jest

Migration

CODE
滚动查看更多
Migrate this JavaScript code to TypeScript:
- Add type definitions
- Create interfaces
- Update imports
Composer Tips
  • Clearly describe the scope
  • Use @ references for related files
  • Review all changes before accepting
  • You can accept changes partially

Tab Completion

Trigger Methods
  • Auto-trigger: Shows while typing
  • Manual: Shows after pause
Accepting Completions
ActionShortcut
Accept allTab
Accept word by wordCmd/Ctrl + →
CancelEsc
Completion Types
  • Single line completion
  • Multi-line completion
  • Function body completion
  • Comment completion
Improving Completion Quality

Good Comments

JAVASCRIPT
滚动查看更多
// Calculate days between two dates
// Returns negative if date2 is before date1
function daysBetween(date1, date2) {

Clear Function Signature

TYPESCRIPT
滚动查看更多
function validateEmail(email: string): boolean {

Related Context

JAVASCRIPT
滚动查看更多
const users = await fetchUsers();
// Completion will be more accurate
const activeUsers = users.filter(

Configuration

Model Selection
  1. Open Settings (Cmd/Ctrl + ,)
  2. Search "model"
  3. Select AI model:
    • Claude 3.5 Sonnet (recommended)
    • GPT-4
    • GPT-4 Turbo
Common Settings

Privacy Mode

JSON
滚动查看更多
"cursor.privacy.mode": "enabled"

Autocomplete Delay

JSON
滚动查看更多
"cursor.autocomplete.delay": 200

Trigger Length

JSON
滚动查看更多
"cursor.autocomplete.triggerLength": 2
.cursorrules File

Create .cursorrules in project root:

CODE
滚动查看更多
# Project Standards
- Use TypeScript for all new files
- Follow ESLint rules strictly
- Use functional React components
- Style with Tailwind CSS

# Code Style
- Variables: camelCase
- Components: PascalCase
- Files: kebab-case

# Documentation
- JSDoc comments for functions
- Inline comments for complex logic

# Testing
- Jest for unit tests
- React Testing Library for components
- Minimum 80% coverage
Custom Docs
  1. Open Settings
  2. Find Docs configuration
  3. Add custom documentation URLs
  4. Use @Docs in Chat

Prompt Examples

Code Review
CODE
滚动查看更多
@file.ts
Review this file for:
1. Code quality issues
2. Potential bugs
3. Performance problems
4. Security vulnerabilities
5. Suggest improvements
Architecture Analysis
CODE
滚动查看更多
@Codebase
Analyze the project architecture:
- What's the overall structure?
- What are the main modules?
- How do they communicate?
- Any architectural concerns?
Learning Codebase
CODE
滚动查看更多
@src/
I'm new to this project. Explain:
- What does this directory do?
- What are the key files?
- How does data flow through it?
Debugging
CODE
滚动查看更多
This code throws an error:

<error>
TypeError: Cannot read property 'map' of undefined
</error>

Related code:
@component.tsx

How do I fix this?
Feature Planning
CODE
滚动查看更多
I want to add dark mode to this app.
@Codebase

Suggest:
- Which files need changes?
- What's the best approach?
- Any existing patterns to follow?
Refactoring Plan
CODE
滚动查看更多
@component.tsx
This component is 500+ lines.
How should I split it?
- Follow React best practices
- Maintain functionality
- Improve testability

Best Practices

Effective Prompting
  1. Provide clear context
  2. Specify expected behavior
  3. Mention tech stack
  4. Include edge cases
Getting Better Results
  • Use @ references extensively
  • Select relevant code before asking
  • Be specific about requirements
  • Iterate with follow-up questions
Common Mistakes
  • Vague instructions
  • Missing context
  • Not using @ references
  • Accepting without review

Troubleshooting

Inaccurate Completions
  • Add more context
  • Use type annotations
  • Write clear comments
  • Reference related files with @
Composer Changes Too Much
  • Be more specific about scope
  • Execute in smaller steps
  • Use @ to limit files
API Rate Limits
  • Free: Limited requests
  • Pro: More quota
  • Consider using local models

相关 Cheat Sheets

1v1免费职业咨询
logo

Follow Us

linkedinfacebooktwitterinstagramweiboyoutubebilibilitiktokxigua

We Accept

/image/layout/pay-paypal.png/image/layout/pay-visa.png/image/layout/pay-master-card.png/image/layout/pay-airwallex.png/image/layout/pay-alipay.png

地址

Level 10b, 144 Edward Street, Brisbane CBD(Headquarter)
Level 2, 171 La Trobe St, Melbourne VIC 3000
四川省成都市武侯区桂溪街道天府大道中段500号D5东方希望天祥广场B座45A13号
Business Hub, 155 Waymouth St, Adelaide SA 5000

Disclaimer

footer-disclaimerfooter-disclaimer

JR Academy acknowledges Traditional Owners of Country throughout Australia and recognises the continuing connection to lands, waters and communities. We pay our respect to Aboriginal and Torres Strait Islander cultures; and to Elders past and present. Aboriginal and Torres Strait Islander peoples should be aware that this website may contain images or names of people who have since passed away.

匠人学院网站上的所有内容,包括课程材料、徽标和匠人学院网站上提供的信息,均受澳大利亚政府知识产权法的保护。严禁未经授权使用、销售、分发、复制或修改。违规行为可能会导致法律诉讼。通过访问我们的网站,您同意尊重我们的知识产权。 JR Academy Pty Ltd 保留所有权利,包括专利、商标和版权。任何侵权行为都将受到法律追究。查看用户协议

© 2017-2025 JR Academy Pty Ltd. All rights reserved.

ABN 26621887572