Cmd K
Overview
Cmd K (also known as "Ctrl K" on Windows/Linux) allows you to generate new code or edit existing code within the editor window.
Prompt Bar
In Cursor, we call the bar that appears when you press Ctrl/Cmd K
the "prompt bar". It works similarly to the AI input box in chat, where you can type normally or use @ symbols to reference other context.
Inline Generation
If no code is selected when you press Ctrl/Cmd K
, Cursor will generate new code based on the prompt you enter in the prompt bar.
Inline Editing
For in-place editing, simply select the code you want to edit and type in the prompt bar.
Follow-up Instructions
After each generation, you can refine the prompt by adding more instructions in the prompt bar and pressing Enter
, and the AI will regenerate based on your follow-up instructions.
Default Context
By default, in addition to the @ symbols you manually include, Cursor will try to find various useful information to improve code generation.
Additional context may include related files, recently viewed files, and more. Once collected, Cursor ranks the context items based on their relevance to your edit/generation and keeps the highest-ranked items in the large language model's context.
Quick Questions
If you press Option/Alt Enter
in the prompt bar, Cursor will answer any questions you have about the selected content and the context you've attached.
The content of this conversation can be used in subsequent generations, so after Cursor responds, you can simply type "do it" to generate code.
Terminal Cmd K
In Cursor's built-in terminal, you can press Ctrl/⌘ K
to open the prompt bar at the bottom of the terminal. This prompt bar allows you to describe what you want to do in the terminal, and Terminal Cmd K will generate the corresponding command. You can accept the command by pressing esc
or run it immediately with Ctrl/⌘ + Enter
.
By default, Terminal Cmd K uses your recent terminal history, your instructions, and any other content you enter in the prompt bar as context.