CursorBeginner

How to Edit Code Inline with Cmd+K in Cursor

Use the inline edit prompt to rewrite a selection in place, generate new code, and review the diff before accepting.

6 minBeginner

Inline edit is Cursor's fastest way to change code without leaving the file. You select code, press Cmd+K, describe the change in plain English, and Cursor rewrites the selection in place with a diff you approve. This guide walks through a real edit from selection to accept.

What you need

  • Cursor installed and signed in
  • A file with some code you want to change
  • A clear, short description of the change

Step 1: Select and open the prompt

Highlight the lines you want to change, then press Cmd+K (Ctrl+K on Windows). A small prompt box appears right above the selection. With nothing selected, Cmd+K instead generates new code at the cursor.

Editor — Cmd+K prompt
Explorer
format.ts
format.ts
1// selection highlighted:
2function toMoney(n) {
3 return "$" + n
4}
5> Cmd+K: add cents and thousands separators, type the param
The inline prompt opens over your selection.

Step 2: Describe the change

Type an instruction, not code. Be specific about the outcome you want. Reference symbols or other files with @ if the edit needs context from elsewhere in the project.

Cmd+K prompt
$Format as USD with two decimals and a thousands separator. Type the parameter as number.
Generating edit...
$

Step 3: Review the diff

Cursor shows the proposed change as a colored diff inline: removed lines in red, added lines in green. Read it before accepting. You can accept, reject, or type a follow-up to refine without starting over.

format.ts (diff)
- function toMoney(n) {
-   return "$" + n
+ function toMoney(n: number) {
+   return n.toLocaleString("en-US", {
+     style: "currency",
+     currency: "USD",
+   })
  }

Step 4: Accept or refine

Press Enter or click Accept to apply the change. If it is close but not right, type a correction like make the currency a parameter and Cursor revises the same selection again.

Inline edit beats chat for local changes
For a change inside one function, Cmd+K is faster than chat because the result lands directly in the file as a reviewable diff. Save chat for questions, planning, and changes that span several files.

Result: a one-line, plain-English instruction turns an untyped string concatenation into a properly typed, locale-aware currency formatter, applied in place after you reviewed the diff.

Watch related tutorials

Tags
#inline-edit#cmd-k#editing#diff