Inline Editing
Select code, press Cmd+K, and describe what you want \u2014 Cursor edits it in place.
What's possible
- Refactor selected code (rename, extract, restructure)
- Convert between patterns (callbacks to async/await, class to function)
- Add error handling, validation, or logging to existing code
- Generate new code at the cursor position from a description
- Fix bugs in a selected block with a plain-English instruction
- Translate code between languages
Getting started
- 1
Select code (or place your cursor)
Highlight the code you want to change. If nothing is selected, Cmd+K generates new code at the cursor position.
- 2
Press Cmd+K
An inline prompt bar appears. Type your instruction — what to change, how to refactor, or what to generate.
- 3
Review the diff
Cursor shows a diff preview of the proposed changes inline. Green for additions, red for removals.
- 4
Accept or reject
Press Enter to accept the changes, or Escape to cancel and revert to the original code.
Example prompts
Refactoring
“Convert this to use async/await instead of .then() chains”
Adding functionality
“Add input validation \u2014 throw if email is empty or invalid”
Bug fix
“Fix the off-by-one error in this loop”
Generating code
“Write a debounce utility function with TypeScript types”
Tips
- Select only the relevant code. Smaller selections give more focused results.
- Be specific in your prompt. “Refactor this” is vague; “extract the validation logic into a separate function” is actionable.
- Use Cmd+K for single-location edits. For changes that span multiple files, use Composer instead.
- You can chain Cmd+K edits \u2014 make one change, select the result, and refine further.