logo
Cursor 完整指南
Vibe Coding

Cursor 完整指南

Cursor 是目前最流行的 AI 编程编辑器,基于 VS Code 打造。本指南将教你如何高效使用 Cursor 进行 AI 辅助编程。

Cursor 完整指南.cursorrules 配置

.cursorrules 配置

.cursorrules 用来定义项目级别的长期规则,让 Cursor 在每次对话中都遵循你的技术栈、代码风格和约束。

#规则层级

Cursor 的规则优先级为:

Team Rules → Project Rules → User Rules

.cursorrules 属于 Project Rules,作用于当前项目。

#规则类型

在 Cursor 中可以创建两种规则:

  • Always Apply:每次对话都生效
  • Apply Manually:需要手动选择后才生效

你可以在 Cursor Settings > Rules, Commands 中创建、管理规则。

#快速创建规则

在命令面板搜索并执行:

New Cursor Rule

或在 Rules 页面点击 + Add Rule 创建规则。

#.cursorrules 示例

markdown
# Project Rules ## Tech Stack - Next.js 14 App Router - TypeScript - Styled-components - Jest for tests ## Code Style - Use functional components with hooks - Prefer named exports - Use async/await for async logic ## Testing - Add unit tests for new utilities - Avoid snapshot tests unless necessary ## Output - Respond in Chinese - Keep code comments concise

#最佳实践

  • 规则写得越具体,输出越稳定
  • 只写项目长期约束,避免临时需求
  • 对团队项目,优先用 Team Rules 统一规范

#下一步

相关路线图