Cursor Tutorial - Using Chat (Cmd L) to Solve General Problems

We’ve already covered two of Cursor’s three core features: Tab and Prompt Bars (Cmd+K). Today, let’s explore the final feature: Chat (Cmd+L).

First, let’s look at what kinds of situations Chat (Cmd+L) is best suited for.

As mentioned in our previous article about Prompt Bars (Cmd+K), Chat (Cmd+L) is mainly designed to solve general problems.

Cursor Chat

Chat (Cmd+L) offers multi-turn conversations, which is perfect for when you encounter abstract or unclear problems that can’t be solved with just one answer.

Through multiple exchanges, AI can gradually understand the details of your problem and provide more accurate and comprehensive answers. This conversation style not only helps you better understand the problem but also guides you to find the best solution.

Chat (Cmd+L) is particularly useful in these scenarios:

  1. Explaining programming concepts and learning new technologies or frameworks
  2. Getting code suggestions and best practices
  3. Debugging and troubleshooting

Basic Features

Just like ChatGPT’s chat window, Cursor’s Chat feature provides the most flexible programming assistance. You can ask any question here.

Cursor Chat Basic Features

However, there are two key differences that make Cursor special:

  1. Quick context referencing using the @ symbol
  2. The ability to Apply code modifications

These features are unique to Cursor. Not only does ChatGPT lack these features, but other code editors don’t offer similar capabilities either.

Apply

Let’s first look at the Apply feature. It’s very convenient as it allows you to easily implement AI’s code suggestions directly into your project.

Cursor Chat Apply

After applying a code block, you can review the diff changes and quickly accept or reject them using the buttons in the top-right corner of the code block in the chat window.

Cursor Chat Apply

While the Apply feature gives Chat (Cmd+L) the ability to modify code, if you have specific code modification needs, it’s actually better to use features specifically designed for code modification:

  1. Prompt Bars (Cmd+K): Excellent for local code modifications
  2. Composer: Specialized in global cross-file modifications

Context References Using @

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

Cursor Chat Context Reference

It’s worth noting that the @ context referencing capability is basically the same in both Chat and Composer.

However, in Prompt Bars (Cmd K), since its main function is local code modification, its @ context referencing ability is somewhat limited.

Context is crucial in AI-assisted programming, which can be understood from the AI’s problem-solving perspective:

AI’s Limitations:

  • While AI knows a lot, it’s not omniscient. Sometimes, it might not be familiar with certain specific technical areas.

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.

Using Context Effectively

How can we use context information effectively?

Using context effectively is like giving AI a “cheat sheet.” This “cheat sheet” should achieve two things:

  1. Highlight key points: Only select truly relevant information, don’t include irrelevant details.
  2. Find the right balance: Provide enough information, but not too much. Too little context means AI might not understand your problem, while too much might overwhelm the AI and increase the chance of hallucinations.

Simply put, you need to give AI just the right amount of information - not too little, not too much - for it to help you most effectively.

Based on whether context comes from the current project or external sources, we can divide context information into two categories:

  1. Internal Information
  2. External Information

Internal Information

Internal information references help Cursor better understand and handle project complexities, leading to more precise answers.

Cursor offers several ways to reference internal information, with context scope ranging from small to large:

Code < Files ≈ Git < Folders < Codebase

This gradually expanding context range allows developers to flexibly choose the most appropriate context information based on the problem’s complexity and scope, resulting in more precise and valuable AI assistance.

Code/Files/Folders

These three options are self-explanatory, and you can choose the appropriate context range based on your needs:

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

Notably, when using Files or Folders level references, if a file is too large, Chat won’t read it all at once but will break it into smaller chunks.

Then, based on your question, it will select the most relevant parts. This helps Cursor answer your questions more quickly and accurately.

Cursor Chat Long Context

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

Additionally, you’ll notice that Prompt Bars (Cmd+K) doesn’t offer broad context referencing capabilities like Folders and Codebase, as Cursor wants Prompt Bars to focus on handling local code.

Git

Git information is like a timeline of your code, showing how it evolved to its current state.

Cursor provides several types of Git-related context information.

Cursor Chat Git

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

  • PR (Diff of Main Branch): The diff between your current branch and the main branch

  • Pending Changes (Commit:Diff with Working State): Code changes in your git working directory that haven’t been added yet.

    • You can use this to quickly generate git commit messages
  • Committed Changes: All commits managed in the code repository

Besides using @Git directly in the chat box, you can also use the Review feature in the AI panel.

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

Cursor Chat Git Preview

Review makes it easier to examine and optimize code in Git commits.

Cursor Chat Git Preview

You can enter custom code review instructions in the input field.

Below that, you can 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 your entire codebase to provide more comprehensive context and suggestions.

This feature is particularly useful for handling large projects or situations requiring cross-file analysis.

Actually, @Codebase uses RAG technology - it vectorizes all files in your current project and stores them locally.

You can check your codebase indexing status in Cursor settings:

Cursor Chat Codebase

In Chat, @Codebase offers two search modes:

Cursor Chat Codebase

embedding mode and reranker mode.

Embedding mode directly searches the local vector database, includes the most relevant chunks in the message request, and returns results to the user.

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

Cursor Chat Codebase

Based on my testing, reranker mode works better when summarizing and organizing comprehensive project information.

External Information

External information is crucial in AI-assisted programming.

It’s like opening a window for AI to see the broader world. With this information, AI isn’t limited to just project internals but can access the latest and most relevant knowledge.

Cursor mainly provides two ways to quickly access external information: @Doc and @Web.

Doc

Using @Doc in Chat lets you bring in documentation to expand AI’s knowledge base.

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

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

Cursor Chat Doc

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

Cursor Chat Doc

You provide the documentation URL, and Cursor automatically fetches all related documents.

Web

The @Web feature allows Chat to search and reference online information when answering questions.

The most direct way is to use @Web in Chat(Cmd+L), which automatically searches for relevant online information.

Cursor Chat Web

You can also @URL to reference information from a single page.

Cursor Chat Web

Context Templates - Notepad

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

Cursor Chat Notepad

With Notepad, you can:

  • Customize context: Enter any information you consider important in Notepad, such as project background, coding standards, or commonly used code snippets.
  • Flexible referencing: You can conveniently reference Notepad content in both Chat and Composer.

Cursor Chat Notepad

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

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

However, ideally, Notepad should support more reference types, allowing us to combine various reference types we discussed above within Notepad.

Summary

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

The key is to use context information effectively to maximize its capabilities.