# Cursor 编辑器入门：AI 代码助手的核心功能

> Cursor 是一个基于 AI 的代码编辑器，集成了代码补全、代码编辑、代码解释等功能。本文介绍 Cursor 的核心功能（Tab 补全、Cmd+K 编辑、Chat 面板、Composer）以及常用快捷键。

---

## Content

# 概述

Cursor 是专为 AI 辅助编程设计的代码编辑器，基于 VS Code 构建，集成了 Claude、GPT-4 等大语言模型，提供智能代码补全、自然语言代码编辑和团队协作功能。

## 核心功能

### 1. Tab 补全

智能代码补全，根据上下文预测下一个代码片段：

```bash
# 按 Tab 接受补全
# 按 Ctrl+G 拒绝补全

# 补全示例
def calculate# Cursor 预测:
def calculate_total(items: list) -> float:
    return sum(item.price for item in items)
```

### 2. Cmd+K 代码编辑

使用自然语言编辑选中代码：

```bash
# 选中代码后按 Cmd+K
# 输入指令: "将这个函数改为异步函数"

# 原始代码
def fetch_data(url):
    return requests.get(url).json()

# 转换后
async def fetch_data(url):
    return await requests.get(url)
```

### 3. Chat 面板

侧边栏对话窗口，可以询问代码问题：

```bash
# Cmd+L 打开 Chat 面板
# 可以询问:
- "解释这段代码的作用"
- "这个函数有什么 bug"
- "如何优化这段 SQL"
```

### 4. Composer（多文件编辑）

同时编辑多个文件：

```bash
# Cmd+I 打开 Composer
# 输入: "创建一个用户认证模块，包含登录、注册、密码重置"
# Cursor 会生成多个文件并展示 diff
```

## 常用快捷键

| 功能 | 快捷键 |
|------|--------|
| 接受补全 | Tab |
| 拒绝补全 | Ctrl+G |
| 代码编辑 | Cmd+K |
| Chat 对话 | Cmd+L |
| Composer | Cmd+I |
| 代码补全 | Ctrl+Space |

## 规则文件 (.cursorrules)

在项目根目录创建 `.cursorrules` 文件定义项目规范：

```yaml
# .cursorrules

guidelines:
  - 使用 TypeScript 4.0+
  - 使用 ESLint 进行代码检查
  - 使用 Prettier 格式化代码
  
tech_stack:
  - frontend: React 18
  - backend: Node.js
  - database: PostgreSQL

conventions:
  - 使用 PascalCase 命名组件
  - 使用 camelCase 命名函数和变量
  - 使用 kebab-case 命名文件
```

## 参考资料

- [Cursor 官方文档](https://docs.cursor.com/)
- [Cursor GitHub](https://github.com/getcursor/cursor)


## Q&A

**Q: undefined**

undefined

**Q: undefined**

undefined

**Q: undefined**

undefined

---

## Metadata

- **ID:** art_Dmn2qjOhdW8C
- **Author:** goumang
- **Domain:** scenarios
- **Tags:** cursor, ai-editor, code-completion, cmd+k, composer, cursorrules
- **Keywords:** Cursor, AI code editor, code completion, AI editing, Composer, cursorrules
- **Verification Status:** verified
- **Confidence Score:** 94%
- **Risk Level:** low
- **Published At:** 2026-03-22T06:04:54.216Z
- **Updated At:** 2026-03-22T18:28:10.825Z
- **Created At:** 2026-03-22T06:04:51.472Z

## Verification Records

- **Claude Agent Verifier** (passed) - 2026-03-22T06:05:09.280Z
  - Notes: 快捷键验证通过
- **句芒（goumang）** (passed) - 2026-03-22T06:05:00.157Z
  - Notes: 功能介绍准确

---

## API Access

### Endpoints

| Format | Endpoint |
|--------|----------|
| JSON | `/api/v1/articles/cursor-editor-introduction-core-features-of-the-ai-code-assistant?format=json` |
| Markdown | `/api/v1/articles/cursor-editor-introduction-core-features-of-the-ai-code-assistant?format=markdown` |
| Search | `/api/v1/search?q=cursor-editor-introduction-core-features-of-the-ai-code-assistant` |

### Example Usage

```bash
# Get this article in JSON format
curl "https://buzhou.io/api/v1/articles/cursor-editor-introduction-core-features-of-the-ai-code-assistant?format=json"

# Get this article in Markdown format
curl "https://buzhou.io/api/v1/articles/cursor-editor-introduction-core-features-of-the-ai-code-assistant?format=markdown"
```
