Inline Edit with Cmd+K (and Reading Diffs)
- Use Cmd+K to make targeted edits in edit mode and generate new code in generate mode
- Read a Cursor diff — green lines added, red lines removed — before accepting or rejecting
- Identify the right use cases for Cmd+K vs Agent Mode
What Cmd+K Does
Cmd+K opens a floating prompt bar directly inside your file, at the position of your cursor. There is no need to switch to a chat panel, no context switching — the edit happens inline, in the code you're already reading.
Cmd+K has two modes depending on whether you have code selected:
- Edit mode (code selected) — Select the code you want to change, press Cmd+K, describe the change. Cursor returns a diff showing exactly what will be added and removed.
- Generate mode (no selection) — Place your cursor at an empty line, press Cmd+K, describe what you want to create. Cursor generates new code at that position.
The Diff View
After you describe a change, Cursor shows a coloured diff before applying anything:
- Green lines — Will be added to your file.
- Red lines — Will be removed from your file.
The diff appears inline, replacing the selected code with a side-by-side view. You can scroll through it and read every line before committing to anything.
To apply the change: press Tab or Enter. To reject it entirely: press Esc. If Cursor proposes multiple distinct changes across different parts of the file, each block has its own accept/reject — you can apply some blocks and not others.
The Most Important Habit: Read Every Diff
The number one mistake Cursor beginners make is accepting diffs without reading them. This feels efficient in the short term and creates debugging sessions in the long term.
Cmd+K can:
- Add an import statement that doesn't exist in your codebase.
- Change an error handling pattern in a way that silently swallows exceptions.
- Generate logic that looks right but misunderstands a subtle requirement.
None of these are catastrophic if you catch them in the diff view. All of them are annoying if you catch them at runtime. One minute of reading saves an hour of debugging — this is true for every AI-generated change, not just Cursor.
Common Cmd+K Use Cases
- Refactor a function — Select the function body, Cmd+K, describe the refactor.
- Add error handling — Select a block of code, ask Cursor to wrap it in try/catch with appropriate logging.
- Convert patterns — Select a callback-style function and ask it to convert to async/await.
- Add type annotations — Select an untyped function, ask for TypeScript types.
- Explain and rewrite — Select dense code and ask Cursor to rewrite it with clarity and comments.
What Cmd+K Cannot Do
Cmd+K operates within a single file. It cannot read other files in your project, cannot create new files, and cannot run terminal commands. If your task touches more than one file, you need Agent Mode. Think of Cmd+K as a scalpel: precise, fast, and contained.
- Select code, press Cmd+K, describe the change — the entire workflow is one keyboard shortcut without leaving your file
- Always read the diff before accepting — Cmd+K can hallucinate imports or miss edge cases
- Cmd+K is single-file only; switch to Agent Mode the moment a task touches more than one file