Knowledge card L1 · Basic prompts informational

Master the Cmd-K Inline Edit Loop

What it is

Inline edit (Cmd-K / Ctrl-K) lets you select code, describe a change in plain language, and apply it in place as a reviewable diff — the fastest, most controlled way to use AI in Cursor.

the Cmd-K loopSelectInstructReviewAccept
Select, instruct, review, accept — the core inline-edit rhythm.

Why it works

Because you select the exact lines first, the model's scope is unambiguous and the change is local. You see a diff before accepting, so you stay in control. It's tighter than chat (which regenerates and explains) for the small, frequent edits that make up most coding.

When to use it

Small, well-defined changes on code you can see: rename within a block, add a guard clause, convert a loop, write a docstring, extract a variable. Your default for 'change this bit'.

When not to use it

Cross-file or exploratory work — that's what chat and agents are for. Forcing a repo-wide change through inline edit means doing it file by file by hand.

Prompt

Select the code, hit Cmd-K, and be specific about the change only:
"Add an early return if `items` is empty."
"Convert this to async/await, keep the error handling."
"Extract the price calc into a named function."
Then read the diff before accepting.

Example

You select a nested .then() chain, press Cmd-K, type 'convert to async/await', and accept the diff — a 20-second change that would've taken a paragraph of chat and a copy-paste.

Advanced version

Chain small inline edits instead of one big instruction: guard clause, then extract function, then rename — each a clean diff you approve. Pair with @-context when the selection alone doesn't carry enough information for the change.

Common mistakes

  • Writing a whole-file instruction into an edit scoped to one selection.
  • Accepting diffs without reading them because the change 'looked right'.
  • Reaching for inline edit on multi-file changes it isn't built for.

Related