程序员的生产力神器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官网(https://cursor.com/) 下载对应系统的安装包,可能需要用魔(ti)法(zi)访问官网。

  • 下载完成后,双击运行安装包,根据提示完成安装。

  • 首次启动需要到cursor官网进行登录,建议使用邮箱注册,因为可以使用临时邮箱(

https://temp-mail.org/zh/10minutemail)注册,方便新账号福利到期快捷更换临时邮箱,继续享受新账号试用期福利。

  • 每次新账号的注册在试用期可以获得150次高级模型的调用,账号有效期是两周,任何一个先达到,福利都失效。

●账号到期或使用次数超限后,完全关闭cursor,执行cursor-reset-win.exe程序(https://github.com/isboyjc/cursor-reset?tab=readme-ov-file),重置试用期。

●重置试用期后,打开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 撰写项目研发文档

在项目目录下创建一个项目研发文档,写好你对此项目研发的需求场景、目标、研发步骤等内容,如下:

复制代码
# 项目研发文档          ## 需求场景试剂检测企业在处理医院项目名称与企业项目名称匹配时,通常需要耗费大量人力和时间。为了提高工作效率,开发一款自动化匹配程序,通过语义相似性分析技术,自动识别并匹配相似的项目名称 ## 目标开发一款能够自动处理和匹配项目名称的程序,减少人工匹配的工作量,提高匹配的准确性和效率。## 研发步骤#### 1. 数据准备- 生成测试数据:- 使用utils/data_generator.py生成企业和医院的项目清单。- 企业数据包含以下列:- 序号: 项目序号- 企业项目名: 企业项目名称- 试剂名: 试剂名称- 医院数据包含以下列:- 序号: 项目序号- 医院项目名: 医院项目名称- 数据保存在data/input/qiye.xlsx和data/input/yiyuan.xlsx中。- 读取数据:- 在application.py中,使用pandas读取企业和医院的项目清单。 - 提取企业项目名和医院项目名列表,供后续处理使用。          #### 2. 向量化处理- 调用向量化服务:- 使用ApiCaller类调用外部向量化服务,将项目名称转化为向量。 - 向量化服务的URL配置在config/application_dev.yaml中。- 批量处理:- 每次最多处理5个项目名称,分批调用向量化服务。- 记录向量化过程的日志信息,便于调试和监控。          #### 3. 相似度计算- 计算余弦相似度:- 使用numpy计算项目名称向量之间的余弦相似度。- 对每个医院项目名称,找到最相似的企业项目名称。- 记录匹配结果:- 将匹配结果和相似度分数记录在日志中。- 输出匹配质量统计信息,包括最小、最大、平均和中位数相似度。          #### 4. 结果输出- 保存匹配结果:- vector.csv:- 列名包括企业项目名和向量。- 保存企业项目名称及其向量表示。- yiyuan_new.xlsx:- 列名包括序号、医院项目名、匹配的企业项目名和匹配相似度。- 保存医院项目名称及其匹配结果和相似度分数。- 日志记录:- 记录处理过程中的关键步骤和错误信息。- 输出低相似度警告,提醒用户检查可能的错误匹配。          ## 配置信息- 向量化服务:- URL: http://localhost:8001/vec/batch/encode/v1- 请求类型:post- 请求体示例:          {"txts": [xxx","xxxx"]}- 响应体示例:          {"success": true,"message": "","code": "0","data": {"vecs": [[0.023102,...,-0.0025],[-0.02305,...,-0.03245016]]}}- 文件路径:          - 企业项目清单:data/input/qiye.xlsx- 医院项目清单:data/input/yiyuan.xlsx- 向量数据:data/input/vector.csv- 匹配结果:data/output/yiyuan_new.xlsx          通过以上研发实现步骤,开发团队可以更清晰地理解项目的实现过程,并高效地进行开发和测试。 

3.4 注意

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 https://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~

相关推荐
云泽8083 小时前
Visual Studio 2026 新手保姆级教程:环境搭建、界面优化与编译器配置详解
开发语言·c++·c·开发工具·visual studio
武雄(小星Ai)1 天前
2026年7月 AI 编程工具横评:Claude Code vs Cursor vs GitHub Copilot 实测对比
ai·开发工具·claude·cursor·对比评测
redreamSo1 天前
32 个 AI 编程工具的配置都放哪,这个仓库整理清楚了
ai编程·claude·cursor
AI大模型-小雄3 天前
2026 年 AI 工具怎么选?ChatGPT、Codex 和其他 AI 工具适合哪些人?
人工智能·gpt·chatgpt·开发工具·codex·ai工具
唠点键盘之外的3 天前
10 Spring Boot + 大模型:Java 项目接入 AI 的三种姿势
java·spring boot·aigc·cursor
仙逆GPT5 天前
Cursor Agent一直卡住?自动执行和权限确认怎么排查
ai编程·cursor·ai agent·代码审查·cursor agent
R0OT6 天前
在git bash中使用Cursor CLI
cursor
qingmiaozhuan6 天前
电脑录屏没有声音还能补救吗?音频采集链路详解及4种技术方案
前端·电脑·音视频·开发工具·电脑录屏·电脑录屏软件
赵大仁6 天前
Cursor vs Claude Code vs Copilot:2026 年 AI 编程工具怎么选
人工智能·ai编程·cursor·github copilot·claude code
AI大模型-小雄7 天前
ChatGPT 上传文件失败怎么办?从格式、大小到账号状态逐项排查
gpt·chatgpt·ai编程·开发工具·codex·ai办公·chatgpt pro