Home Understanding Cursor's Chat Feature: A Comprehensive Guide to AI-Assisted Problem Solving

Understanding Cursor's Chat Feature: A Comprehensive Guide to AI-Assisted Problem Solving

Cursor offers three core AI-assisted programming features: the Tab feature, Prompt box (Cmd+K), and Chat (Cmd+L). Having already explored the first two features, this article focuses on the final piece - the powerful Chat (Cmd+L) functionality.

What scenarios is Chat (Cmd+L) best suited for?

As mentioned in our previous article about the Prompt box (Cmd+K) feature, Chat (Cmd+L) specializes in solving "general problems."

cursor-chat-chat-1

Chat (Cmd+L) provides multi-turn conversations. When you encounter abstract or unclear issues, a single response may not resolve all your questions. Through multiple exchanges, AI can gradually clarify the details of the problem, delivering more accurate and comprehensive answers. This conversational approach not only helps you better understand the problem but also guides you toward finding the optimal solution.

Therefore, Chat (Cmd+L) is particularly well-suited for:

  1. Answering programming concept questions, learning new technologies or frameworks
  2. Obtaining code suggestions and best practices
  3. Debugging and troubleshooting

Basic Features

Similar to ChatGPT's chat window, Cursor's Chat function offers the most flexible programming assistance capabilities. You can ask any question in this space.

cursor-chat-chat-base2

However, there are two key differences that make Cursor stand out:

  1. Context quick reference capability based on @
  2. Code modification "Apply" capability

These features are unique to Cursor. Not only does ChatGPT lack these functions, but other code editors haven't provided similar capabilities either.

Apply

First, let's look at the Apply feature. This convenient function allows you to easily implement AI code suggestions directly into your project.

Ccursor-chat-apply-accept

After applying a code block, you can view the diff content of the modifications and quickly process them by clicking the "accept" or "reject" buttons in the upper right corner of the code block in the chat window.

Although the Apply capability gives the chat function (Cmd+L) code modification abilities, if you have "specific" code modification needs, it's actually recommended to use features specifically designed for code modification:

  1. Prompt box (Cmd+K): Excels at "local" code modification
  2. Composer: Specializes in "global" cross-file modifications

Context References with @

In Cursor's AI input fields, such as the Prompt box (Cmd K), Chat, or Composer, you can reference context by typing the @ symbol.

cursor-chat-context-menu

It's worth noting that in Chat and Composer, the @ context reference capabilities are essentially consistent. However, in the Prompt box (Cmd K), since its function is mainly to make local code modifications, its @ context reference capability is somewhat limited.

In AI-assisted programming, the use of context is crucial, which can be understood from the perspective of AI problem-solving:

AI's inherent limitations:

  • While AI knows many things, it's not omniscient. Sometimes, it may not be familiar with certain specific technical domains.

Problem specificity:

  • Each project has its unique structure, logic, and requirements. Without context, AI struggles to understand how to solve problems specific to your current project's scenario.

Using Context Effectively

How can you use context information effectively?

Using context information effectively is like giving AI a "cheat sheet." This "cheat sheet" should accomplish two things:

  1. Focus on what matters: Select only truly relevant information, don't include irrelevant material.
  2. Practice moderation: Provide enough information, but not too much. Too little information might prevent AI from understanding your problem, while too much might overwhelm the AI, increasing the likelihood of hallucinations.

Simply put, you need to give AI just the right amount of information - neither too little nor too much - so it can best help you solve problems.

Based on whether context is obtained from the current project or external sources, context information can be divided into two categories:

  1. Internal Information
  2. External Information

Internal Information

Internal information references enable Cursor to better understand and handle the complexities within a project, thereby obtaining the most precise answers.

Cursor offers multiple ways to reference internal information. Looking at them comparatively, their information scope ranges from small to large in this order:

Code < Files ≈ Git < Folders < Codebase

This gradually expanding context range design allows developers to flexibly choose the most appropriate context information based on the complexity and impact range of the problem, thus obtaining more precise and valuable AI assistance.

Code/Files/Folders

The meaning is clear from the literal interpretation, and you can choose the appropriate context range according to your needs:

  1. Code (code snippets): Allows you to reference specific code snippets in the current file
  2. Files: Lets you reference the entire content of a file (including image files)
  3. Folders: Enables you to reference all files in an entire folder

Notably, when you use Files or Folders level references, if a file contains too much content, Chat won't read it all at once but will divide the file into smaller chunks. Then, based on your question, it will select the most relevant parts. This approach allows Cursor to answer your questions more quickly and accurately.

cursor-chat-long-context

If you want to provide the entire content of a file or folder to the AI, you can enable the long context feature.

Additionally, you'll notice that the Prompt box (Cmd+K) doesn't offer large-scale context reference capabilities, such as Folders and Codebase. Cursor intends for the Prompt box to focus on handling local code.

Git

The information carried in Git is like a timeline of your code, allowing you to clearly see how the code has evolved to its current state.

Cursor provides the following Git-related context information:

cursor-chat-git-context

With this context information, it becomes very convenient to review, optimize, and fix bugs in your code:

  • PR (Diff of Main Branch): The diff between the current branch and the main branch
  • Pending changes (Commit: Diff with Working State): Code information in your git working area that hasn't been added yet
    • You can use this to quickly generate git commit messages
  • Committed Changes: All commits managed in the code repository

In addition to directly using @Git to reference information in the chat box, you can also use the Review feature in the AI panel.

Currently, the Review feature is still in Beta and needs to be enabled in Cursor settings.

Review makes it more convenient to review and optimize code in Git commits.

In the input box, you can enter custom code review instructions. Below, you can directly select the code context you want to review, similar to what @Git provides.

Codebase

@Codebase is a powerful Cursor feature that allows AI to scan the entire codebase to provide more comprehensive context and suggestions. This feature is particularly suitable for handling large projects or situations requiring cross-file analysis.

The principle behind @Codebase is the use of RAG technology, which vectorizes all files in your current project and stores them locally.

In Cursor settings, you can see the current project's codebase index status:

cursor-chat-codebase-status

@Codebase in Chat provides two search modes:

cursor-chat-codebase-search-mode

Embedding mode and reranker mode.

Embedding mode directly searches in the local vectorized library, bringing the most relevant chunks of information from the search into the request message, then returning results to the user.

Reranker mode adds reordering and thinking steps, making it more complex.

Based on personal testing, reranker mode produces better results when summarizing more comprehensive information about a project.

External Information

Obtaining external information is very important in AI-assisted programming.

It's like opening a window for AI, allowing it to see a broader world. With this information, AI is no longer limited to the internal project but can access the latest and most relevant knowledge.

Cursor primarily provides two ways to quickly obtain external information: @Doc and @Web.

Doc

Using @Doc in Chat allows you to introduce documentation to expand AI's knowledge base.

For example, if your current project uses a specific technology stack, you can specify a particular version or the latest version of technical documentation to meet the requirements of your current technology stack.

Cursor provides some common built-in documentation, such as React-related technical docs.

cursor-chat-doc-context

In settings, you can also manually introduce external documentation you need.

cursor-chat-doc-context-add

You provide the URL of the documentation, and Cursor automatically helps you capture all related documents.

Web

The @Web feature allows Chat to search and reference information on the web when answering questions.

The most direct way to use it is by using @Web directly in Chat (Cmd+L), which will automatically search for relevant web information.

Cursor Web Search

Alternatively, you can use @URL to introduce information from a single page.

Cursor Web URL

Context Templates - Notepad

Notepad is a powerful context template feature provided by Cursor. It functions like your personal notebook, where you can save various information and easily reference it when needed.

Using Notepad, you can:

  • Customize context: Enter any information you consider important in Notepad, such as project background, coding standards, or frequently used code snippets.
  • Flexible references: Whether in Chat or Composer, you can conveniently reference Notepad content.

Cursor Notepad Usage

The advantage of Notepad lies in providing a unified and personalized way to manage and use context information. This not only increases your efficiency in interacting with AI but also ensures that AI always understands your project background and requirements, thereby providing more accurate and relevant assistance.

In Notepad, you can enter text information and reference files to build context templates.

Ideally, Notepad should support more reference types, allowing you to combine various reference types discussed above within Notepad.

Conclusion

Overall, Chat (Cmd+L) is an extremely powerful tool that can help you handle various programming scenarios, from simple code issues to complex project discussions.

Most importantly, using context information appropriately is essential to maximize its capabilities.

Tag: Cursor Tutorial Chat Feature AI Programming Problem Solving Code Assistance