Cursor Tutorial - Are You Really Making the Most of the Prompt Bar (Cmd K)?

  1. How to quickly generate git commit messages in Cursor?
  2. What are the tips for using the Prompt Bar (Cmd K)?
  3. Do you know the difference between the Prompt Bar (Cmd K) and Chat (Cmd L)?

Let’s explore Cursor’s second main AI-assisted programming feature: the Prompt Bar (Cmd K), and find answers to these questions below.

What is the Prompt Bar (Cmd K)?

If the Tab feature is the most direct form of AI-assisted coding (generating code directly), then the Prompt Bar (Cmd K) is the fastest way for users to guide AI, making up for AI’s limitations in fully understanding user intentions.

The Prompt Bar (Cmd K) is the quickest way to interact with AI in Cursor. It’s like having a programming assistant on standby, ready to help you instantly.

Cursor's Prompt Bar

Unlike the Chat feature (Cmd L), the Prompt Bar (Cmd K) is mainly used for generating or modifying specific code sections, while Chat (Cmd L) is designed for broader coding discussions, supporting multiple rounds of conversation and addressing more general programming questions.

Cursor’s Prompt Bar comes in two types:

  • Code Editor Prompt Bar: Used in the code editor for adding or editing code.
  • Terminal Prompt Bar: Used in the terminal for generating terminal commands.

Code Editor Prompt Bar

In the code editor, pressing Cmd K (or Ctrl K on Windows/Linux) will bring up the Prompt Bar (as shown below), where you can enter prompts to generate code suggestions.

Cursor's Code Editor Prompt Bar

Context Information Used

The quality of generated code depends on the effectiveness of context information.

When using the Prompt Bar in the code editor, Cursor automatically tries to find useful information to improve code generation. Besides manually included @ symbols, it also considers:

  • Files related to your current code edits
  • Recently viewed files

Cursor ranks context items based on their relevance to your edits/generation and keeps the most relevant items for the large language model’s context.

Inline Generation

If you press Cmd K without selecting any code, Cursor will generate new code based on what you type in the Prompt Bar.

Inline Generation

Inline Editing

If you press Cmd K with code selected, Cursor will modify the selected code based on your prompt.

Inline Editing

Terminal Prompt Bar

In Cursor’s built-in terminal, you can press Cmd K (or Ctrl K on Windows/Linux) to open the Prompt Bar at the bottom of the terminal.

Terminal Prompt Bar

  1. In the Prompt Bar, simply describe what you want to do in the terminal.
  2. Cursor will automatically write a terminal command based on your description.
  3. If you like the suggested command:
    • Press Esc to put the command in the terminal without executing it.
    • Press Cmd + Enter to execute the command immediately.

Context Information Used

The Terminal Prompt Bar considers the following context by default:

  • Recent terminal history
  • Any other content in the Prompt Bar

Tips

Follow-up Instructions

When using AI to generate code or answers, we often find that the first result isn’t perfect. That’s where “follow-up instructions” come in handy. It’s like having a conversation with AI, allowing you to guide it step by step until you get the desired result.

For example, if AI’s first code generation isn’t quite right, you can simply type “add error handling to this function” in the Prompt Bar. Then press Enter, and AI will modify the code based on your new instructions. You don’t need to start over; you can keep improving on what’s already there.

Quick Answers

Sometimes, we need to quickly understand what a piece of code does or get simple information without generating or modifying code. This is where the quick answer feature shines.

If you press Option/Alt Enter in the Prompt Bar, Cursor will immediately answer any questions about the selected content and related context (without generating or modifying code).

Quick Answers

This feature is particularly useful because:

  1. It quickly answers your questions, helping you better understand the code.
  2. You don’t need to switch to the chat window; you can get answers right in the editor.
  3. The conversation content is remembered for use in future operations.

Quickly Generate Git Commit Messages

You can use the Terminal Prompt Bar to quickly generate git commit messages.

Steps:

  1. In the terminal, type ‘git diff | cat’ to see recent changes.
  2. Then type ‘git add .’ to add all changes to the staging area.
  3. Press Cmd K, type ‘git commit message’ in the Prompt Bar, and Cursor will generate a git commit command with a generated commit message.
  4. Press Cmd + Enter to execute the command - it’s that simple!

Summary

By using the Prompt Bar (Cmd K), you can quickly generate and modify code, create git commit messages, and even get quick answers about your code. These features can help you code more efficiently, save time, and boost your productivity.

Stay tuned for our next blog post about Cursor’s third main AI-assisted programming feature - the Chat function (Cmd L).