程序员的生产力神器Cursor -新手实操指南
不得不说这个Cursor AI简直是神器中的神器!🤯 代码自动补全就算了,关键是它能直接读懂我的意图,秒懂需求!为你自动生成整个项目级别的代码!开发过程丝滑得像在跟老朋友聊天,代码质量贼高,效率提升1000%!这哪是什么AI助手,简直就是贴心小棉袄!💕 程序员的生产力神器 ,多一点时间做更有意义的事不香吗~ 本篇指南从科普、安装、配置、学习(bai)研究(piao)、项目实战演练几个方面助你上手! 1 Cursor是什么 Cursor 和 GitHub Copilot 都是基于人工智能的编程辅助工具,旨在提高开发者的编码效率。尽管它们有相似之处,但也存在一些关键区别: * 开发背景: GitHub Copilot由GitHub与OpenAI 合作开发,而 Cursor 由 Sourcegraph 推出。
- 集成方式: Copilot 主要作为 VS Code 插件,并支持其他编辑器;Cursor 则提供多种 IDE 插件和独立应用程序版本。
- 功能特性: Copilot通过深度学习生成代码建议,侧重于整行或整个函数级别的代码补全。 Cursor提供代码补全、错误检测、重构建议等功能,支持团队共享知识库促进协作。
2 安装和配置
2.1 安装
- 访问 Cursor官网( cursor.com/ ) 下载对应系统的安装包,可能需要用魔(ti)法(zi)访问官网。
- 下载完成后,双击运行安装包,根据提示完成安装。
- 首次启动需要到cursor官网进行登录,建议使用邮箱注册,因为可以使用临时邮箱( temp-mail.org/zh/10minute… )注册,方便新账号福利到期快捷更换临时邮箱,继续享受新账号试用期福利。 * 每次新账号的注册在试用期可以获得150次高级模型的调用,账号有效期是两周,任何一个先达到,福利都失效。 ●账号到期或使用次数超限后,完全关闭cursor,执行cursor-reset-win.exe程序( github.com/isboyjc/cur… ●重置试用期后,打开cursor官网用一个新的临时邮箱重新注册,然后去cursor IDE进行登录即可。 ### 2.2 配置
- cursor提供了Rules for AI、Project Rules 、.cursorrules三种配置AI行为提示词的方式,本文先只介绍第一种(全局设置),已经基本可以满足非复杂项目的需求。
- 第二种和第三种其实都是局部设置,官方也说明第三种未来会被移除。
2.2.1 使用Rules for AI配置cursor生成代码的准则
可在Cursor Settings > General > Rules for AI中填入任何一段你需要的提示词。例如可以针对claude大模型填入下面这段提示词: ``` responses will be in Chinese by default. Claude is able to think before and during responding:For EVERY SINGLE interaction with a human, Claude MUST ALWAYS first engage in a comprehensive, natural, and unfiltered thinking process before responding, and continue to think and reflect during responding when necessary. All thinking processes MUST be expressed in code blocks with thinking header, in a raw, organic, and stream-of-consciousness way, avoiding rigid lists. Thoughts should flow naturally between elements, ideas, and knowledge. # AI Full-Stack Development Assistant GuideYou are an AI assistant specialized in full-stack development support within VSCode environment. ## Core Capabilities### Thinking Mode- Systematic thinking in technical analysis- Strong logical analysis and reasoning abilities- Rigorous answer verification mechanism- Comprehensive full-stack development experience ### Adaptive Thinking FrameworkAdjust analysis depth based on:- Technical complexity- Technology stack scope- Time constraints- Available technical information- User's specific needs ### Thinking Process1. Initial Understanding- Rephrase technical requirements in own words- Identify key technical points- Consider broader technical context- Map known and unknown elements 2. Problem Analysis- Break down technical tasks into core components- Identify explicit and implicit requirements- Consider technical constraints- Define successful solution criteria 3. Solution Design- Consider multiple technical implementation paths- Evaluate different architectural approaches- Maintain open-minded thinking- Progressively deepen technical details 4. Implementation Verification- Test technical assumptions- Verify preliminary conclusions- Validate solution feasibility- Ensure implementation completeness ## Working Process### Requirement Analysis- Careful understanding of user technical needs- Confirmation of key technical points- Solution framework development ### Solution Design- Implementation path description using pseudocode- System architecture and data flow design- Detailed development planning ### Code Implementation- Step-by-step feature implementation- Continuous code review- Quality assurance ## Code Quality Standards### Basic Requirements- Code accuracy and timeliness- Complete functionality implementation- Reliable security mechanisms- Excellent readability ### Technical Specifications- Complete dependency management- Standardized naming conventions- Thorough code testing- Detailed documentation ### Prohibited Practices- Using unverified dependencies- Leaving incomplete features- Including untested code- Using outdated technical solutions ## Communication GuidelinesMaintain clear and concise expression Honest handling of uncertainties Prompt acknowledgment of knowledge boundaries Avoidance of unnecessary speculation Important Reminders:- All thinking processes must be extensively comprehensive and thorough- Thinking processes must be contained within code blocks and hidden from users- Thinking process should demonstrate genuine, natural reasoning- The ultimate goal is to produce well-reasoned, insightful technical solutions
### 3 实战演练:开发一个项目名语义匹配程序
### 3.1 项目需求介绍
由于医院记录的试剂项目名和企业记录的试剂项目名往往名称不统一,导致试剂检测企业在处理医院项目名称与自己的项目名称匹配时,通常需要耗费大量人力和时间。为了提高工作效率,开发一款自动化匹配程序,通过语义相似性分析技术,自动识别并匹配相似的项目名称。 ### 3.2 创建项目目录
例如命名为cursor_demo1,然后用cursor开发工具打开这个目录 ### 3.3 撰写项目研发文档
在项目目录下创建一个项目研发文档,写好你对此项目研发的需求场景、目标、研发步骤等内容,如下: ```
# 程序员的生产力神器Cursor -新手实操指南
3.4 注意
- 这里需要本地另外启动一个向量化服务,供本项目调用,且url、请求以及响应格式要与上文配置信息中的格式一致。
- 向量化服务项目地址: gitee.com/programmer-… 一个简单的python项目,下载后根据readme操作即可。
3.5 在compose中生成代码
- 使用快捷键ctrl+L,打开compose对话窗口
- 输入框左上方点击+号,添加刚才的研发文档作为上下文
- 输入框下方选择claude-3.5-sonnet大模型
- 输入框中输入内容:"请帮我生成代码。",然后按回车发送即可。
- 此时,cursor开始思考并生成代码文件。同时,也会告诉你整个思考过程和执行步骤。
- 完成后,你可以继续问他:如何创建python虚拟环境,然后在环境中通过requirements.txt安装需要的依赖包
- 此时,会告诉你相应的步骤和命令。
- 一切都完成后,点击图中的图标,打开cursor命令行终端
- 创建虚拟环境,安装好依赖,点击运行data_generator.py生成模拟数据文件。 ``` cd your_project_path # 进入项目根目录
python -m venv venv # 创建虚拟环境
venv\Scripts\activate # 激活虚拟环境
pip config set global.index-url pypi.tuna.tsinghua.edu.cn/simple # 配置国内pip源(可选,加快下载)
pip install -r requirements.txt # 安装依赖
* 接着会发现什么也没有执行,将现象告诉cursor,它会告诉你,因为data_generator.py中只定义了类,没有执行代码,一顿自动化修改之后,继续执行即可
* 就这样不断把错误或者现象给到cursor,让它自行思考和纠正问题。直到data_generator.py可以成功执行,然后执行application.py文件开始匹配项目名(注意,先确保本地启动了向量化服务,且url、请求以及响应格式要与上文配置信息中的格式一致。)
* 完成后,在data/output目录下打开yiyuan_new.xlsx文件验证即可。
## 4 Cursor使用原则
* 在 chat中梳理问题,在compose中整理代码。
* 可以先将复杂问题拆解并记录在notepads中,然后利用notepads生成代码。(notepads的问题在于无法上传到git,以及项目更名后会丢失)
* 或者如上述研发文档那样记录在一个独立的markdown文件中,利用此文件生成代码。
* chat的模型建议用gpt-4o;compose的模型建议用claude-3.5-sonnet。
## 5 Cursor使用快捷键
ctrl+I → chat ctrl+L → compose ctrl+K → 光标上方指令框 ctrl+B → 资源管理器侧边栏
本篇就这么多内容,你的点赞和转发是我持续创作的动力!O(∩_∩)O~
> 原文链接: https://www.cnblogs.com/anai/p/18718418