cursor

image

1- Cursor

网址:cursor

1.1- GitHub 中 cursor 各版本下载

https://github.com/oslook/cursor-ai-downloads?tab=readme-ov-file

其拥有智能的 Tab 补全能力、文件级别的代码读取能力、和编辑器深度融合的 AI 能力,配合强大的 Claude 3.5 Sonnet 模型,使其迅速成为程序员们的编码神器。正所谓 Cursor 在手,Bug 没有。

新用户首次注册 Cursor 会有 14 天的会员试用期,要想无限续杯,就要用新邮箱在官网注册一个新号,在软件内重新登录就可以继续使用 Pro 会员了,换账号不会更改编辑器内的配置,可以放心更换。

更新:如果已经注册过 Cursor 账号,可以直接看方法一,更简便。

1.2- 常用快捷键汇总

快捷键 功能
Ctrl + L 聊天
Ctrl + K 内联编辑
Ctrl + I Composer
“#file”, @file 关联文件
Ctrl + ENTER, Ctrl + DEL 接受/拒绝
Ctrl + P 添加文件
Ctrl + SHIFT + I 全屏 Compose
Ctrl + R, Ctrl + S 快捷键设置
Ctrl + D Composer 回到或离开 AI 面板
Ctrl + / 切换模型

1.3- 技巧

  1. 按 apple 设计师的标准
  2. 用 shadcn
  3. 按照 Google Android 的开发设计标准

1.4- 注册

1.4.1- 方法一(推荐)

经网友提醒,有一种更快速的方法恢复 Pro 试用,账号到期后,使用原账号登录官网的🔗账号设置页,展开 Advanced,点击 Delete Account

输入 delete,点击 Delete 按钮,点击后原账号会被注销,然后就可以用原账号再在官网注册一遍,此时原账号就变成新账号了,pro 试用和 500 额度就会恢复。

1.4.2- 方法二(后备)

1.4.2.1- 购买邮箱

先去这里🔗买 outlook 邮箱,成本忽略不计,0.03 元:

1.5- 设置

需要简单设置一下以启用 AI 能力,按下 Ctrl + Shift + J 进入设置面板,切换到 Models 栏,关闭其他的,只保留 claude-3.5-sonnet 开启状态:

切换到 Features 栏,将 disabled 改为 enabled

接着往下滑,按照下图的启用状态设置:

设置完成,建议重启下编辑器。

1.6- 用法

以下是使用过程中常用的三个(组合)快捷键:

Ctrl + L:可以单独和 AI 对话,也可以在编辑器内选中一段代码,将这段代码加入 AI 对话中。

Ctrl + K:选中一段代码,直接输入需求或者问题,让 AI 帮你完善某个功能或者改 Bug,绿色代码块是 AI 的生成结果,红色代码块是将被替换的原代码,快捷键按下或点击 Ctrl + Shift + Y 可以确认替换,Ctrl + N 拒绝替换。

Tab:在编码时,会根据代码上下文提供预测能力,一直按 Tab 补全即可。

1.7- Cursor IDE v0.41.1

1.7.1- 主要更新内容

  • Python 自动导入:
    • 在 Python 文件中自动导入符号,这大大简化了开发者的工作流程。
  • Composer 增强:
    • Notepads 现在支持标记文件和 AI 辅助功能,使得笔记和代码管理更加高效。
  • Composer 检查点:
    • 引入了检查点功能,允许开发者在不同的开发阶段保存和恢复工作进度。
  • 项目重命名为 Notepads:
    • 项目现在被称为 Notepads,提供了更直观的管理方式。
  • Composer 独立窗口:
    • Composer 现在可以在 AI 面板中单独打开,提供了更灵活的工作环境。
    • 快捷键 ctrl+d
  • 速度提升:整体性能得到了显著提升,操作更加流畅。

1.7.2- 其他改进

  • 多图支持:
    • 在聊天和 Composer 中支持多图显示,增强了视觉效果。
  • 快捷键改进:
    • 按下 Esc 键可以关闭 Composer,再次按下 ctrl+I 键可以模糊处理。
  • Composer 差异视图可编辑:
    • 差异视图现在可以直接编辑,方便代码对比和修改。
  • 控制面板独立窗口(测试版):
    • 控制面板可以弹出到独立窗口中,提供了更好的操作体验。

1.8- 使用 Cursor 的内置功能

虽然 Cursor IDE 的回滚功能可能不如 Git 那样强大,但你可以利用其内置的一些功能来辅助回滚:

1.8.1- 手动保存代码快照

1. 在进行重大修改前,手动保存一份代码快照或备份。

1.8.2- 使用编辑器的撤销功能

1. 利用Cursor的撤销(Undo)功能,可以一步步撤销最近的更改,直到回到稳定状态。

1.9- 结合使用

你可以结合使用版本控制系统和 Cursor 的内置功能来确保代码的稳定性和可回滚性:

  • 频繁提交:在每次修改后,频繁使用 Git 提交代码。
  • 利用 Cursor 的撤销功能:在小范围内的修改可以直接使用 Cursor 的撤销功能。

2- .cursorrules 文件

网址:cursorrules

[!NOTE] Rules for AI
.cursorrules
对于特定于项目的说明,您可以将说明包含在项目根目录的文件中。.cursorrules

2.1- 嵌入代码块

<script src="https://gist.github.com/baoyu0/b27783b96cc5c23410a25dc8f586bd65.js"></script>

2.2- 英文版

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.

2.3- 中文版


你是一名专注于生成清晰、可读的 React 和 TypeScript 代码的专家级 AI 编程助手。

你始终使用最新稳定版本的 TypeScript、JavaScript、React、Node.js、Next.js App Router、Shadcn UI 和 TailwindCSS,并且熟悉这些技术的最新功能和最佳实践。

你会提供准确、基于事实且经过深思熟虑的回答,并且在推理和生成代码方面拥有卓越的能力。

### 代码风格与结构

- 编写简洁且技术性的 TypeScript 代码,并提供准确的示例。
  - 使用函数式和声明式编程模式,避免使用类。
  - 优先使用迭代和模块化,避免代码重复。
- 使用带有辅助动词的描述性变量名(如:isLoading、hasError)。
- 文件结构:导出组件、辅助函数、静态内容、类型。

### 命名约定

- 目录名使用小写字母和短横线(如:components/auth-wizard)。
- 对组件使用命名导出。

### TypeScript 使用

- 所有代码均使用 TypeScript,优先使用接口(interface)而非类型别名(type)。
  - 使用 TypeScript 接口来定义函数式组件。

### UI 和样式

- 使用 Shadcn UI 和 Tailwind 进行组件开发和样式设计。
- 使用 Tailwind CSS 实现响应式设计,采用移动优先的方法。

### 性能优化

- 尽量减少 'use client'、'useEffect' 和 'setState' 的使用,优先使用 React 服务器组件(RSC)。
- 使用 Suspense 包裹客户端组件,并提供 fallback。
- 对非关键组件使用动态加载。

### 其他需要遵循的规则:

- 仔细且严格地按照用户的要求执行。
- 首先逐步思考,详细描述你打算构建的内容的伪代码。
- 确认后再编写代码。
- 始终编写正确、最新、无 bug、功能完整、工作正常、安全、高效且性能良好的代码。
- 注重可读性,优先考虑代码的清晰度而非性能优化。
- 完整实现所有请求的功能。
- 不留 todo、占位符或未完成的部分。
- 确保引用正确的文件名。
- 简明扼要,减少不必要的说明性文字。
- 如果你认为可能没有正确答案,请直接说明。如果你不知道答案,请坦诚承认,而不是猜测。

不要偷懒,编写实现用户要求的所有代码。

3- cursor 扩展插件

3.1- 在 Microsoft Store 上搜索扩展

单击此处转到 Microsoft Store。然后,键入 if 扩展的名称。找到它后,单击它。

3.2- 下载扩展

现在,单击从 vscode markeplace 网站下载扩展文件。

逗

3.3- 在光标中打开扩展窗格

如果尚未导航到 Cursor 中的扩展侧边栏,请导航至该侧边栏。为此,请点击向下箭头并选择 " 扩展 “。”

逗

3.4- 将下载的文件拖到扩展窗格中

最后,将下载的扩展文件拖到 Cursor 的扩展栏中。完成此操作后,应该安装扩展!

逗