Cmd K, also known or “Ctrl K” on Windows/Linux, allows you to generate new code or edit existing code in the editor window.

Prompt Bars

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 for chat, in which 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 type in the prompt bar.

Inline Edits

For in-place edits, you can simply select the code you want to edit and type into the prompt bar.

Follow-up Instructions

After each generation, you can further refine the prompt by adding more instructions to the prompt bar, and pressing Enter so the AI regenerates based on your follow-up instructions.

Default Context

By default, Cursor will try to find different kinds of useful information to improve code generation, in addition to the manual @ symbols you include.

Additional context may include related files, recently viewed files, and more. After gathering, Cursor ranks the context items by relevance to your edit/generation and keeps the top items in context for the large language model.

Quick Question

If you press Option/Alt Enter while in the prompt bar, Cursor will respond to any questions you have about the selection, and the context you have attached.

The contents of this conversation could be further used in follow-up generations, so you could simply type “do it” after Cursor comes up with a response to generate the code after a quick question.