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.
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.
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.
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.
- 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.
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
1:42:18
28:14
41:09
9:47
8:23
52:31