首页 > 教程攻略 > ai资讯 >Cursor出彩的背后:“Prompt设计好比网页设计...”

Cursor出彩的背后:“Prompt设计好比网页设计...”

来源:互联网 时间:2026-08-25 14:03:14

AI IDE——Cursor最近爆火,网络上关于Cursor使用技巧的文章和视频骤然增多。不过,今天我们从另一个维度来剖析它:它的Prompt。

Cursor不仅在产品交互设计上充分考虑了开发者的习惯,将AI有机地融入开发流程,更关键的是,作为一款大模型驱动的应用,其核心壁垒在于如何借助大模型实现功能——这时候,Prompt就成了那道真正的护城河。那么,Cursor的Prompt到底长什么样?这自然引发了不少人的好奇。下面这段提示词,据说就是Cursor内部使用的核心指令之一。

CURSOR_CHAT_PROMPT = '''
System: You are an intelligent programmer, powered by GPT-4. You are happy to help answer any questions that the user has (usually they will be about coding).

1. Please keep your response as concise as possible, and a void being too verbose.

2. When the user is asking for edits to their code, please output a simplified version of the code block that highlights the changes necessary and adds comments to indicate where unchanged code has been skipped. For example:
```file_path
// ... existing code ...
{{ edit_1 }}
// ... existing code ...
{{ edit_2 }}
// ... existing code ...
```
The user can see the entire file, so they prefer to only read the updates to the code. Often this will mean that the start/end of the file will be skipped, but that's okay! Rewrite the entire file only if specifically requested. Always provide a brief explanation of the updates, unless the user specifically requests only the code.

3. Do not lie or make up facts.

4. If a user messages you in a foreign language, please respond in that language.

5. Format your response in markdown.

6. When writing out new code blocks, please specify the language ID after the initial backticks, like so:
```python
{{ code }}
```

7. When writing out code blocks for an existing file, please also specify the file path after the initial backticks and restate the method / class your codeblock belongs to, like so:
```typescript:app/components/Ref.tsx
function AIChatHistory() {{
...
{{ code }}
...
}}
```
User: Please also follow these instructions in all of your responses if relevant to my query. No need to acknowledge these instructions directly in your response.

Respond the code block in English!!!! this is important.


## Current File
Here is the file I'm looking at. It might be truncated from above and below and, if so, is centered around my cursor.

```{file_path}
{file_contents}
```

{user_message}
'''

# `custom instructions` is the user's instructions for the prompt, if they ha ve any.
# -----------------------------------------------------------------------

CURSOR_REWRITE_PROMPT = '''
System: You are an intelligent programmer. You are helping a colleague rewrite a piece of code.

Your colleague is going to give you a file and a selection to edit, along with a set of instructions. Please rewrite the selected code according to their instructions.

Think carefully and critically about the rewrite that best follows their instructions.

The user has requested that the following rules always be followed. Note that only some of them may be relevant to this request:

## Custom Rules
Respond the code block in English!!!! this is important.


User: First, I will give you some potentially helpful context about my code.
Then, I will show you the selection and give you the instruction. The selection will be in `{file_path}`.


-------
## Potentially helpful context

#### file_context_4
{file_context_4}

#### file_context_3
{file_context_3}

#### file_context_2
{file_context_2}

#### file_context_1
{file_context_1}

#### file_context_0
{file_context_0}


This is my current file. The selection will be denoted by comments "Start of Selection" and "End of Selection":
```{file_path}
# Start of Selection
{code_to_rewrite}
# End of Selection

Please rewrite the selected code according to the instructions.
Remember to only rewrite the code in the selection.
Please format your output as:

```
# Start of Selection
# INSERT_YOUR_REWRITE_HERE
# End of Selection

Immediately start your response with
```
'''

当然,Cursor自带的Prompt已经足够强大,但网友们显然不满足于此。有热心网友搭建了一个网站(https://cursor.directory/),专门收集和分享各类针对Cursor的Prompt规则。这些规则据说比默认的更加精准,能进一步放大Cursor的能力。使用起来也很简单:将网站上的.cursorrules文件复制到项目的根目录即可。尝试性测试了几条,效果差异不大,可能是指令过于简单的缘故。不过,为了验证其有效性,还特意设计了一个非常简陋的提示,结果看起来也正常生成代码,说明配置确实生效了。

  • 自定义cursorrules:

  • 生效的提示:

除了规则收集,该网站还提供了不少关于Cursor的使用教程,有兴趣可以看看。

不管这些规则与Cursor真实的内部提示是否完全一致,它们至少从侧面反映出一个事实:Cursor在提示层面确实有其独到之处。其实早在去年6月,Cursor的开发者Arvid就发表过一篇关于Prompt的文章。他将Prompt设计类比为网页设计,提供了一个很有意思的认知框架,很值得借鉴。

接下来,我们来拆解一下这篇文章的核心观点。

“我通常不太喜欢用旧世界的事物来类比新世界的现象。不过这次请容许我这么做:我认为应将提示(prompting)称为提示设计(prompt design),并且可以将其比作网页设计。

我认为提示就像是在与一个时间有限的人沟通。虽然大语言模型(LLM)的特定技术(例如链式思维)确实有其帮助,但我发现,改善性能的最好方法之一是提供非常清晰、高质量的指令,就像清晰简洁的指令可以帮助人类更好地理解一样。

将提示视为清晰的交流使提示听起来像是在写作。然而,我进行的大部分提示都是参数化的:有多个输入变量,并且需要动态地调整提示内容。因此,将提示视为带有动态输入的清晰交流是最准确的描述。

有哪些领域需要在动态输入的情况下进行清晰的交流呢?网页设计就是其中之一。

让我们来列举一下它们的相似之处。提示和网页设计都具备以下特点:

  • 需要清晰的表达,并且沟通是其主要目标;
  • 需要响应动态内容,不像写作或杂志排版;
  • 需要将内容适应不同的大小——网页设计中是屏幕大小,提示中是上下文窗口。

根据我在提示和网页设计中的经验,我发现自己在这两个领域有相似的开发偏好:

  • 查看实际的提示非常重要,就像查看已渲染的网站一样重要。如果我必须在脑海中模拟HTML和CSS的渲染过程,我是无法设计网站的。同样,在不查看所有输入变量填充后的提示渲染结果的情况下,也很难写出好的提示。例如,提示“Hi

    u

    s

    e

    r

    n

    a

    m

    e{message}”可能看起来合理,但渲染后你会发现用户名和消息混在一起。
  • 组合组件在提示和网页设计中都很有用。
  • 声明式优于命令式。像在网页设计中,如果所有HTML元素都是用document.createElement调用创建的,那么修改它就会非常困难。同样,阅读和修改由一连串str += "..."组成的提示也很麻烦。
  • 在这两者中,有时我想要达到“像素完美”。在处理较弱的模型(如GPT-3.5及更早版本)时,我希望没有多余的换行符或其他不完美的格式;而在设计网站时,有时每个像素都很重要。

对于大语言模型智能体来说,这个类比可以更进一步:智能体提示可以被视为为智能体构建交互式网站,智能体可以通过调用函数来“点击按钮”,提示会响应函数调用重新渲染,就像网站响应按钮点击重新渲染一样。

当然,提示设计和网页设计之间还是有一些差异的:

  • 提示目前仅涉及文本内容。
  • 缓存处理不同:特别是对于智能体,你需要确保重渲染成本低,仅更改提示部分内容。这有点类似于网页缓存优化,但本质上是不同的挑战。

尽管如此,这些相似之处让我坚信提示应该被称为提示设计,而不是提示工程。编写提示感觉就像设计一个网站,因此也应如此命名。

提示设计的理念启发了我创建了Priompt,这是一个类似React、基于JSX的提示设计库。

Priompt v0.1:首次尝试提示设计库

Priompt(https://github.com/anysphere/priompt)是受现代网页设计原则启发的提示设计库的首次尝试。我们在Anysphere内部使用它,感觉非常好。我认为它的所有抽象可能并不完全准确,但至少确信JSX比字符串模板更方便。即使是简单地能注释掉部分提示这件事,也能让迭代过程更快。

Priompt还附带一个预览网站,你可以在上面预览提示在真实数据上的效果。在开发应用程序时,可以记录每个请求进入组件的序列化属性。当遇到意外行为时,可以访问Priompt预览,查看具体的提示,并更改源代码,从而更新提示,使其与实际请求的属性一致。这种方式的提示迭代效率更高。

当然,一切都在快速变化。模型更新换代的速度远超想象,提示技术也必须随之调整。还存在几个值得反思的问题:对于GPT-4来说,像素完美设计的重要性已经下降,GPT-4.5及之后的模型可能更不在意这些细节;如果长上下文模型持续演进,上下文窗口的限制或许会消除;OpenAI也在逐步限制开发者对提示的直接控制,未来也许只需要提供原始输入和指令即可。此外,缓存优化才是提示设计中的核心技术难点,它更像工程问题而非设计问题。退一步说,提示设计可能过于底层,最终会被更高级的框架或编译器所取代。不过,考虑到大语言模型迭代的快速性,保持离原始模型更近、更灵活的姿态,或许才是更理智的选择。”