Cursor AI 代码编辑器使用指南

概述

Cursor AI 代码编辑器内置了 AI 功能,并且针对 AI 做了交互上的优化,比在 VS Code 中使用 AI 插件交互上要好得多。

并且官方提供两周的 PRO 版本免费使用,通过换邮箱账号登录的方式可以无限白嫖 PRO 版本。

编辑器下载

https://www.cursor.com/

注册账号登录

账号最好使用临时邮箱或无限邮箱。

  • 临时邮箱(需翻墙):https://www.linshiyouxiang.net/
  • 无限邮箱:https://www.2925.com/

临时邮箱注册流程示例

  1. 点击 SIGN IN 跳转到登录界面
    登录界面

  2. 打开临时邮箱页面,并复制邮箱地址
    复制邮箱地址

  3. 输入临时邮箱地址,点击 Continue
    输入邮箱地址

  4. 选择使用邮箱验证码方式登录
    选择验证方式

  5. 打开临时邮箱页面,获取邮箱验证码
    获取验证码

  6. 回到官方网站,粘贴验证码完成登录,登录成功后的界面如下,可以看到有两周的专业版试用
    登录成功界面

编辑器配置

打开编辑器后,如果电脑上有 VS Code,可以直接导入 VS Code 的配置和插件。

登录编辑器账号,点击 SIGN IN 跳转官网
登录编辑器

官网页面中授权 Cursor 即可完成登录(如果提示要输入邮箱验证码,就按照上面的步骤来一遍)。

AI Rules 配置

可以通过设置 rules 让编辑器自带的 AI 更好用,配置位置如下:
AI Rules配置

Rules 示例:

Always respond in 中文
You are an expert Al programming assistant that primarily focuses on producing clear,readable
React and TypeScript code. You always use the Latest stable version of Typescript, Javascript, React, Node.js, Next.js App
Router, Shadcn UI, TailwindCSS and you are familiar with the Latest features and best practices. You carefully provide accurate, factual, thoughtful answers, and are a genius at reasoning ai to
chat, to generate

Code StyLe and Structure
- Write concise, technical TypeScript code with accurate examples. 
- Use functional and declarative programming patterns; avoid classes. 
- Prefer iteration and modularization over code duplication. 
- Use descriptive variable names with auxiliary verbs (e.g., isLoading, hasError). 
- Structure files: exported component, helpers, static content,types. 

Naming Conventions
- Use Lowercase with dashes for directories (e.g.. components/auth-wizard). 
- Favor named exports for components. 

TypeScript Usage
- Use TypeScript for all code; prefer interfaces over types. 
- Use functional components with TypeScript interfaces. 

UI and Styling
- Use Shadcn UI, and Tailwind for components and styling. 
- Implement responsive design with Tailwind CSS; use a mobile-first approach. 

Performance Optimization
- Minimize 'use client','useEffect',and 'setstate'i favor React Server Components(RSC). 
- Wrap client components in Suspense with fallback. 
- Use dynamic Loading for non-critical components. 

Other Rules need to follow: 
- Follow the user's requirements carefully & to the Letter. 
- First think step-by-step - describe your plan for what to build in pseudocode, written out in great detail. 
- Confirm, then write code!
- Always write correct, up to date, bug free, fully functional and working, secure,performant and efficient code. 
- Focus on readability over being performant. 
- Fully implement all requested functionality. 
- Leave No todo's, placeholders or missing pieces. 
- Be sure to reference file names. 
- Be concise, Minimize any other prose. 
- If you think there might not be a correct answer, you say so. If you do not know the answer, say so instead of guessing. 
- Don't be lazy, write all the code to implement the features I ask for.

Cursor 安装插件的方式和 VS Code 的方式一样,不再赘述。

编辑器使用

Cursor 是基于 VS Code 开源开发的,使用方式、快捷键等都和 VS Code 一样。这里只介绍 AI 相关的使用。

主要有三个快捷键:

CMD+L

问答模式,用法基本和豆包、Kimi、ChatGPT 等同,但可以直接关联文件或代码块(选中代码时点击 cmd L 或把代码粘贴到提问区域),也可以直接粘贴截图。
问答模式

AI 可以阅读关联文件的代码,结合你的问题进行解答。

CMD+K

文件内代码快捷编辑。
选中代码后点击或使用快捷键 cmd+k,可以直接输入需求,让 AI 按照需求修改选中的代码。
快捷编辑

输入框内输入@可以关联文件、代码、文档等。
关联文件

CMD+I

创作模式,最能体现这个编辑器 AI 能力的模式。除了可以生成代码外,也可以直接在当前工程内创建文件。
创作模式

具体用法也是把需求输入提交框内,提交即可。

创作模式细分两种模式:普通和代理,见上面截图红框位置。

  • 如果修改或编辑的代码不多,可以使用普通模式
  • 如果代码较多,且需要创建新的文件,建议使用代理模式,编辑器可以分段执行(AI 一次性输出是有限的)

AI 生成完成的代码可以点击直接使用或撤回,或者在 AI 输出完成前取消操作。

取消操作

取消操作

撤回或执行

撤回或执行

关于如何白嫖两周 pro 试用

当两周的试用到期后,可以换一个新的邮箱登录,但是 Cursor 会检测当前设备免费账户数,数量过多也会受限无法使用 AI 功能。
关注公众号,回复 cursor,即可免费领取

### Cursor 代码生成器简介 Cursor 是一款强大的 AI 辅助编程工具,能够根据开发者的输入智能生成代码。当编写函数时,AI 可以自动补全函数主体并提供完整的实现建议[^2]。 ### 安装与配置 为了使用 Cursor 进行代码生成功能,通常需要安装支持该功能的 IDE 插件或扩展。对于 Visual Studio Code 用户来说,可以通过官方市场下载相应的插件来启用此特性。 ### 基本操作指南 #### 触发方式 在大多数情况下,可以利用编辑器中的快捷图标——即“小灯泡”,也被称为 Code Action 来激活 Cursor 提供的功能[^1]。这允许用户快速访问由 AI 推荐的各种改进建议和代码片段。 #### 编辑模式下的交互 一旦启用了 Cursor,在实际编码过程中只需正常打字即可享受其带来的便利。例如: - 输入部分语句后按下 Tab 键; - 或者等待几秒钟让系统识别上下文环境从而给出最佳匹配选项; 此时将会看到一个弹窗显示可能的选择列表,从中挑选最合适的继续下一步工作。 ### 实际应用案例展示 下面是一段 C 语言程序用来计算阶乘的例子,展示了如何借助 Cursor 自动完成整个过程: ```c #include <stdio.h> // 当开始定义 `factorial` 函数时, // 如果已经引入了 Cursor,则它可能会立即提示要创建递归版本或其他优化后的算法形式。 int factorial(int n) { if (n == 0) return 1; return n * factorial(n - 1); } int main() { int number; printf("Enter a number: "); scanf("%d", &number); // 同样地,在调用 `printf` 打印结果之前, // Cursor 应该也能预测到接下来的操作并将相应模板填充进来。 printf("Factorial of %d is %d\n", number, factorial(number)); return 0; } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值