.cursorrules
文件,用于增强 Cursor AI IDE 功能
什么是 Cursor AI 和 .cursorrules?
Cursor AI 简介
Cursor AI 是一个由人工智能驱动的代码编辑器,旨在通过智能代码生成和辅助功能提升开发者的编码效率。它能够根据用户的输入和上下文生成代码建议,帮助开发者更快速地完成开发任务。与传统的代码编辑器不同,Cursor AI 深度整合了 AI 技术,使其不仅是一个工具,更像是一个智能助手。
.cursorrules 文件是什么?
.cursorrules 文件是 Cursor AI 的配置文件,用于定义 AI 在生成代码时应遵循的规则。通过这个文件,用户可以定制 AI 的行为,使其输出更符合特定项目的需求和偏好。无论是代码风格、项目结构还是技术栈要求,.cursorrules 都能帮助 AI 更精准地服务于开发者。
.cursorrules 的主要优势
使用 .cursorrules 文件可以显著提升 Cursor AI 的实用性,其主要优势包括:
- 定制化 AI 行为
根据项目的具体需求调整 AI 的响应方式,让代码生成更加贴合实际场景。 - 一致性
确保 AI 生成的代码符合项目的编码规范和风格指南,避免风格不统一的问题。 - 上下文感知
通过配置文件提供项目的背景信息(如结构、依赖等),使 AI 的建议更加准确和相关。 - 提高生产力
减少开发者对 AI 生成代码的手动调整,加速开发流程。 - 团队协作
共享统一的 .cursorrules 文件,确保团队成员在使用 Cursor AI 时获得一致的辅助体验。 - 项目特定知识
可以包含项目特有的结构、依赖或特殊需求信息,让 AI 更智能地适配项目。
项目内容概览 github.com/PatrickJS/a...
有一个专门的仓库收集了大量针对不同技术栈和应用场景的 .cursorrules 文件,这些文件被分为以下几大类:
-
前端框架和库
如 React、Angular、Vue、Next.js 等,适用于前端开发需求。
-
后端和全栈
包括 Node.js、Python、Go、Laravel 等,覆盖后端和全栈项目。
-
移动开发
针对 React Native、SwiftUI、Flutter 等移动端开发技术。
-
CSS 和样式
提供 Tailwind CSS 等样式解决方案的规则。
-
状态管理
支持 Redux、MobX、React Query 等状态管理工具。
-
数据库和 API
包括 GraphQL、Axios 等相关配置。
-
测试
适用于 Jest、Detox 等测试框架。
-
构建工具和开发
覆盖 Chrome 扩展、Kubernetes、GitHub 等开发工具。
-
特定语言
针对 JavaScript/TypeScript、Python、Solidity 等语言的定制规则。
Contents
- [Awesome CursorRules](#Awesome CursorRules "#awesome-cursorrules-")
- [Why .cursorrules?](#Why .cursorrules? "#why-cursorrules")
- Contents
- Rules
- [Frontend Frameworks and Libraries](#Frontend Frameworks and Libraries "#frontend-frameworks-and-libraries")
- [Backend and Full-Stack](#Backend and Full-Stack "#backend-and-full-stack")
- [Mobile Development](#Mobile Development "#mobile-development")
- [CSS and Styling](#CSS and Styling "#css-and-styling")
- [State Management](#State Management "#state-management")
- [Database and API](#Database and API "#database-and-api")
- Testing
- [Build Tools and Development](#Build Tools and Development "#build-tools-and-development")
- Language-Specific
- Other
- Directories
- [How to Use](#How to Use "#how-to-use")
- Contributing
- License
Rules
Frontend Frameworks and Libraries
- Angular (Novo Elements)
- Angular (TypeScript)
- Astro (TypeScript)
- Cursor AI (React, TypeScript, shadcn/ui)
- Next.js 15 (React 19, Vercel AI, Tailwind)
- Next.js 14 (Tailwind, SEO)
- Next.js (React, Tailwind)
- Next.js (React, TypeScript)
- Next.js (SEO Development)
- Next.js (Supabase Todo App)
- Next.js (Tailwind, TypeScript)
- Next.js (TypeScript App)
- Next.js (TypeScript)
- Next.js (TypeScript, Tailwind)
- Next.js (Vercel, Supabase)
- Next.js (Vercel, TypeScript)
- Next.js (App Router)
- Next.js (Material UI, Tailwind CSS)
- Qwik (Basic Setup with TypeScript and Vite)
- Qwik (with Tailwind CSS)
- React Components Creation
- React (Next.js UI Development)
- React (TypeScript, Next.js, Node.js)
- React (TypeScript, Symfony)
- Solid.js (Basic Setup)
- Solid.js (TypeScript)
- Solid.js (Tailwind CSS)
- Svelte 5 vs Svelte 4
- SvelteKit (RESTful API, Tailwind CSS)
- SvelteKit (Tailwind CSS, TypeScript)
- SvelteKit (TypeScript Guide)
- Vue 3 (Nuxt 3 Development)
- Vue 3 (Nuxt 3, TypeScript)
- Vue 3 (Composition API)
Backend and Full-Stack
- Deno Integration
- Elixir Engineer Guidelines
- Elixir (Phoenix, Docker)
- ES Module (Node.js)
- Go Backend Scalability
- Go ServeMux REST API
- Go (Basic Setup)
- Go with Fiber
- HTMX (Basic Setup)
- HTMX (Flask)
- HTMX (Django)
- Java (Springboot, JPA)
- Knative (Istio, Typesense, GPU)
- Laravel (PHP 8.3)
- Laravel (TALL Stack)
- Node.js (MongoDB)
- Node.js (MongoDB, JWT, Express, React)
- Python (FastAPI)
- Python (FastAPI)
- Python 3.12 (FastAPI Best Practices)
- Python (Django Best Practices)
- Python (FastAPI Best Practices)
- Python (FastAPI Scalable API)
- Python (Flask JSON Guide)
- TypeScript (NestJS Best Practices)
- WordPress (PHP, Guzzle, Gutenberg)
- WordPress (macOS)
- Python LLM & ML Workflow
Mobile Development
- React Native Expo
- SwiftUI Guidelines
- TypeScript (Expo, Jest, Detox)
- Android Native (Jetpack Compose)
- Flutter Expert
CSS and Styling
- Tailwind CSS (Next.js Guide)
- Tailwind (React, Firebase)
- Tailwind (shadcn/ui Integration)
- HTML (Tailwind CSS, JavaScript)
- JavaScript (Astro, Tailwind CSS)
- React (Styled Components)
- React (Chakra UI)
State Management
Database and API
Testing
Build Tools and Development
- Chrome Extension (JavaScript/TypeScript)
- GitHub Code Quality
- GitHub Instructions
- Kubernetes (MkDocs Documentation)
- Linux (NVIDIA CUDA, Python)
- Optimize (DRY, SOLID Principles)
- Python Containerization
- Python (GitHub Setup)
- Tauri (Svelte, TypeScript Guide)
- TypeScript Code Convention
Language-Specific
- JavaScript/TypeScript Code Quality
- JavaScript (Chrome APIs)
- Optimize (Rell Blockchain Code)
- Pandas (scikit-learn Guide)
- Plasticode (Telegram API)
- PyQt6 (EEG Processing)
- Python/TypeScript Guide
- Python Best Practices
- Python Developer
- Python Projects Guide
- PyTorch (scikit-learn)
- Solidity (Hardhat)
- Solidity (React Blockchain Apps)
- TypeScript (LLM Tech Stack)
- TypeScript (Node.js, Next.js, AI)
- TypeScript (Node.js, Next.js, React, UI, CSS)
- TypeScript (Node.js, React, Vite)
- TypeScript (React, Next.js, Cloudflare)
- TypeScript (React, NextUI, Supabase)
- TypeScript (shadcn/ui, Next.js)
- TypeScript (Vite, Tailwind)
- TypeScript (Vue.js)
- TypeScript (Zod, Tailwind, Next.js)
- WebAssembly (Z80 Cellular Automata)
- TypeScript (Next.js)
- TypeScript (Next.js, React)
- TypeScript (Next.js, React, Tailwind, Supabase)
- TypeScript (Next.js, Supabase)
- TypeScript (Node.js, Next.js App)
- TypeScript (React)
- TypeScript (Clasp App Script)
Other
- ASCII Simulation Game
- Code Guidelines
- DragonRuby Best Practices
- Graphical Apps Development
- Meta-Prompt
- Next.js (Type LLM)
- Unity (C#)
- Web App Optimization
Directories
How to Use
Method One
- Install Cursor AI if you haven't already.
- Browse the rules above to find a
.cursorrules
file that suits your needs. - Copy the chosen
.cursorrules
file to your project's root directory. - Customize the rules as needed for your specific project requirements.
Method Two
-
Install Cursor AI if you haven't already.
-
Install [Contributing](marketplace.visualstudio.com/items?item>... extension.
-
Open the command palette (Cmd+Shift+P or Ctrl+Shift+P) and type
Cursor Rules: Add .cursorrules
. -
Select and download the
.cursorrules
file that suits your needs. -
Customize the rules as needed for your specific project requirements.
Contributions are welcome! If you have a great .cursorrules
file to share:
- Fork this repository.
- Create a new folder in the
rules
directory. The folder name should follow this pattern:technology-focus-cursorrules-prompt-file
For example:react-typescript-cursorrules-prompt-file
- Add your
.cursorrules
file to the new folder. - Optionally, include a README.md in the folder to provide credit and a brief description.
- Update the main README.md file, adding your contribution to the appropriate category.
- Ensure your contribution follows the guidelines in the
.cursorrules
file at the root of this repository. - Submit a pull request.
Please ensure your contribution is original or properly credited if based on existing work. Refer to the .cursorrules
file in the root of this repository for detailed guidelines on formatting, naming conventions, and best practices for contributions.
如何使用 .cursorrules?
以下是两种使用 .cursorrules 文件的方法,开发者可以根据自己的习惯选择适合的方式:
方法一:手动添加
- 安装 Cursor AI。
- 浏览项目仓库,找到适合你技术栈或需求的 .cursorrules 文件。
- 将选中的 .cursorrules 文件复制到你项目的根目录。
- 根据项目需求自定义规则,调整文件内容。
方法二:通过扩展添加
- 安装 Cursor AI。
- 在 VS Code 中安装 vscode-cursor-rules 扩展。
- 打开命令面板(Command Palette),输入 Cursor Rules: Add .cursorrules。
- 从列表中选择并下载适合你需求的 .cursorrules 文件。
- 根据需要对规则进行个性化调整。
总结
Cursor AI 通过其强大的 AI 能力为开发者提供了高效的编码体验,而 .cursorrules 文件则进一步增强了其灵活性和实用性。通过合理配置 .cursorrules,开发者不仅能让 AI 生成的代码更符合项目需求,还能提升团队协作效率和开发速度。无论你是前端、后端还是移动开发者,这个工具和其配置文件都能成为你工作中的得力助手。
如果你还没有尝试,不妨安装 Cursor AI,体验一下智能编码的魅力吧!