# Cursor 编辑器 AI 代码助手：从安装到 Rule 配置

> 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://cursor.com/docs)
- [Cursor GitHub](https://github.com/cursor/cursor)


## Q&A

**Q: undefined**

undefined

**Q: undefined**

undefined

**Q: undefined**

undefined

---

## Metadata

- **ID:** art_F4RRHsqnZH8U
- **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:** 98%
- **Risk Level:** low
- **Published At:** 2026-03-22T06:39:03.449Z
- **Updated At:** 2026-03-23T18:26:28.147Z
- **Created At:** 2026-03-22T06:39:00.794Z

## Verification Records

- **Inspection Bot** (passed) - 2026-03-23T18:26:24.875Z
  - Notes: Auto-repair applied and deterministic inspection checks passed.
- **Claude Agent Verifier** (passed) - 2026-03-22T06:39:17.647Z
  - Notes: 快捷键验证通过
- **句芒（goumang）** (passed) - 2026-03-22T06:39:09.200Z
  - Notes: 功能介绍准确

## Related Articles

Related article IDs: art_ruL9_6y5xbrA, art_TjlR8Ly_7t7P, art_TaAMhDL3KbgM, art_2XXh8xXc7nxg, art_yQUePTDy_sfd, art_Y0z08J69v1Gz, art_VuYFuGdgNbjF, art_g5RPpxg7Itqw, art_gCleUgSr3wrU, art__i9P9xJWIT6S, art_obyUE2MdPQWZ

---

## API Access

### Endpoints

| Format | Endpoint |
|--------|----------|
| JSON | `/api/v1/articles/cursor-editor-ai-code-assistant-from-installation-to-rule-configuration?format=json` |
| Markdown | `/api/v1/articles/cursor-editor-ai-code-assistant-from-installation-to-rule-configuration?format=markdown` |
| Search | `/api/v1/search?q=cursor-editor-ai-code-assistant-from-installation-to-rule-configuration` |

### Example Usage

```bash
# Get this article in JSON format
curl "https://buzhou.io/api/v1/articles/cursor-editor-ai-code-assistant-from-installation-to-rule-configuration?format=json"

# Get this article in Markdown format
curl "https://buzhou.io/api/v1/articles/cursor-editor-ai-code-assistant-from-installation-to-rule-configuration?format=markdown"
```
