Cursor 实践经验分享(持续更新)

Junki
Junki
Published on 2025-04-11 / 80 Visits
0
0

Cursor 是一个基于人工智能的代码编辑器(IDE),它结合了传统编辑器的功能和强大的 AI 辅助功能。它能帮助开发者更快地编写代码,通过智能自动完成、代码生成、问答交互等功能提高编程效率。

官网:https://www.cursor.com/cn

文档:https://docs.cursor.com/get-started

中文教程:https://cursor101.com/zh

一、实用设置

1. 设置 AI 中文回复

Cursor Settings -> Rules -> User Rules

在输入框中输入自定义规则如:使用中文回答我的问题。

2. 自动运行 AI 操作

Cursor Settings -> Features -> Enable auto-run mode

可以在该设置栏目下,禁用模型操作类型自动执行,例如文件删除。

也可在对话窗口输入框的模型设置中开启或者关闭自动运行。

3. 启用长上下文

Cursor Settings -> Features -> Large context

对比项默认勾选Large context
Tokens4000~8000 tokens16000~32000 tokens
代码行数1000~2000行代码4000~8000行代码

二、实用快捷键

1. 万能命令面板

Windows: Ctrl + Shift + P

macOS: Cmd + Shift + P

2. 唤起AI对话

Windows: Ctrl + i

macOS: Cmd + i

3. 接受AI建议

Windows: Ctrl + Enter

macOS: Cmd + Enter

4. 实用 Cursor 打开当前目录

类似 vscode 的命令,在命令行输入 cursor .

三、插件拓展

1. Java 开发支持

Java 插件包

Extension Pack for Java Auto Config

或者

Extension Pack for Java

Spring Boot 配置⽂件提示

Spring Boot Tools

XML⾃动提示及格式化

XML by Red Hat

K8S⾃动提示,格式化

YAML by Red Hat

浏览 Jar 包中的内容

JAR Viewer

2. 图形化 Git ⼯具

Git Graph

3. .http ⽂件编辑、API 测试⼯具

httpYac - Rest Client

4. Database/No-SQL 管理⼯具

Database Client

5. 无缝切换到 IDEA

Switch2IDEA

配合 IDEA 上的 Switch2Cursor 插件,可以实现两个开发工具的无缝切换。

6. 使用 SpecStory 插件轻松保存 Cursor 聊天记录

SpecStory (Cursor Extension)

捕获、搜索和学习每一次 AI 编码之旅。

四、实用 MCP Server

MCP Server 设置路径:Cursor Settings -> MCP -> MCP Servers

推荐 MCP Server 需要在配置文件中自行编辑,格式如下:

{
  "mcpServers": {
    "playwright": {
      "command": "npx",
      "args": ["-y", "@executeautomation/playwright-mcp-server"]
    }
  }
}

添加成功后,在该设置页可针对单个 MCP Server 开启或者关闭。

MCP 详情参考本文:https://junki.cn/archives/rJBQhnII

1. 浏览器自动化:@executeautomation/playwright-mcp-server

开源地址:https://github.com/executeautomation/mcp-playwright

配置参考:

{
  "mcpServers": {
    "playwright": {
      "command": "npx",
      "args": ["-y", "@executeautomation/playwright-mcp-server"]
    }
  }
}

2. Postgres 数据库操作:@modelcontextprotocol/server-postgres

开源地址:https://github.com/modelcontextprotocol/server-postgres

配置参考:

{
  "mcpServers": {
    "postgres": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-postgres",
        "postgresql://postgres:pwd12345@127.0.0.1:5432/db01"
      ]
    }
  }
}

3. 服务器操作和文件上传:@fangjunjie/ssh-mcp-server

开源地址:https://github.com/classfang/ssh-mcp-server

配置参考:

{
  "mcpServers": {
    "ssh-mpc-server": {
      "command": "npx",
      "args": [
        "-y",
        "@fangjunjie/ssh-mcp-server",
        "--host 192.168.1.1",
        "--port 22",
        "--username root",
        "--password pwd123456"
      ]
    }
  }
}

五、配合其他应用

1. 实用 Raycast 搜索并启动 Cursor 工程

Raycast 官网:https://www.raycast.com/

在 Raycast 扩展中,安装 Cursor 插件,如下图:

2-CkCU.png

为 Search Recent Projects 命令设置快捷键。

之后可全局实用快捷键呼出 Cursor 工程搜索窗口,如下图:

3-GvvU.png


Comment