Basics
Cursor Inline Edit: Editing Code in Place with Cmd+K
Inline edit lets you make quick, targeted code changes without opening the chat panel. Select the code you want to change, press Cmd+K on Mac or Ctrl+K on Windows and Linux, type an instruction such as "Convert this to an async function", and press Enter. Cursor applies the edit to the selection in place, and follow-up instructions refine it.
On this page
What is inline edit in Cursor?
Inline edit is a prompt that opens on your selection and rewrites that selection in place, without the chat panel. You stay in the editor, the prompt appears at the code you highlighted, and the result lands on the lines you picked. Cursor's help page describes the job as quick, targeted code changes.
Cmd+K on a helper — rename the variable, not the contract
0:38 · narratedRead this demo as text
- The fix lives inside filterResults — three lines, one local variable. Select just the body, then Cmd+K instead of Agent.
- One instruction, one variable, one file. The diff comes back inside the exact selection — read every renamed line before you touch Accept.
- Accepted. filterResults still takes the same arguments and returns the same shape. Source Control shows exactly one changed file — the boundary held.
Practice next: Practice this yourself in the hands-on module.
Simulated Cursor 3.12 (macOS, light) — beta educational reconstruction, not the real product.
The selection is doing two jobs at once. It says which code you are talking about, and it is also where Cursor applies the change, so a careless selection costs you more than a careless instruction does.
Undershooting and overshooting fail differently. Select too little and the edit is right inside the selection while the caller three lines below still expects the old signature, so the file stops compiling and it reads like the model's mistake. Select the whole file and a one-line request comes back as a diff you have to read line by line, which is most of the review cost you were avoiding by not opening Agent.
My own rule used to be to select exactly the lines you want changed. That is not quite right, and taken literally it is what produces the undershoot. Select the lines you want changed plus whatever has to stay consistent with them. Most of the time that means the whole function rather than the one line inside it.
Inline edit applies the change to the code you selected. When the change has to touch several files, or reason about code you have not opened, that is Agent's job instead. The handoff keeps your selection, so nothing is lost by starting here and moving up. The last section has the keystroke.
This exact topic is a hands-on Lesson: Make One Small Change and Review the Diff — about 6 minutes, free to read. Or try it live in the simulator →
Rather do it than read about it? Run 11 interactive Cursor walkthroughs in a simulated editor. Free, no account needed.
How do I use inline edit?
The loop is five steps, and the fifth one, refining what came back, is the step that tends to get dropped. Cursor documents the sequence like this.
- 1Select the code you want to change.
- 2Press
Cmd+Kon Mac, orCtrl+Kon Windows and Linux. - 3Type your instructions. For example, "Convert this to an async function."
- 4Press Enter. Cursor applies the edit to your selected code.
- 5To refine, add follow-up instructions and press Enter again.
One small change, read every hunk
0:33 · narratedRead this demo as text
- Open the file with the label. Select just line 12. That selection is the blast radius. Cursor should only touch what you highlighted.
- One line? Use Inline Edit. Command-K. Not Agent. Type the exact reword, then wait for the hunk.
- Read every line of that hunk before you Accept. Then check Source Control. One modified file. That is your receipt.
Practice next: Practice this yourself in the hands-on module.
Simulated Cursor 3.12 (macOS, light) — beta educational reconstruction, not the real product.
The widget is smaller than a chat panel and sits in a different place. In Cursor 3An older release label for Cursor's multi-agent interface; current product guidance calls the active surface the Agents Window. Press Enter for the full definition..12 on macOS it is a panel inserted into the file, between the line above your selection and the selection itself, so the code below shifts down instead of being covered up.
The placeholder reads Edit selected code. Around the input sit a scope control labeled Edit Selection, a circular up-arrow that submits, and a close button.
That inserted-panel detail sounds cosmetic, and mostly it is, though it does explain the fifth step. The prompt stays where it was after you submit, with an Add a follow-up input underneath it, so refining the edit is a second sentence in the same place, not a fresh attempt.
Skipping that step costs more than it looks. A proposal that comes back nearly right gets closed, the line gets hand-typed, and nothing is damaged, since a rejected proposal leaves the file exactly as it was. What you have done is type the change twice when one more sentence into the same prompt would have finished it.
What happens after I press Enter?
The change arrives as a proposal you accept or reject, rather than as an edit already made. In Cursor 3An older release label for Cursor's multi-agent interface; current product guidance calls the active surface the Agents Window. Press Enter for the full definition..12 on macOS the removed line renders red with the added line green beneath it, both inside the file, and the widget header switches to Reject and Accept with the Cmd+Enter chord printed alongside. Each hunk also carries its own Undo (Cmd+N) and Keep (Cmd+Y) buttons at its right edge, and the tab shows an unsaved dot while the proposal is pending.
Reading the hunk before you touch Accept is the habit worth building. When we staged these states in Cursor 3An older release label for Cursor's multi-agent interface; current product guidance calls the active surface the Agents Window. Press Enter for the full definition..12 for this site's UI reference captures, a one-line reword came back with a stray blank line attached that nobody had asked for. Harmless, that one. It arrived inside the same green block as the line we had actually asked for, so the only way to catch it was to read both.
Accepting clears every one of those decorations at once.
Red and green are pending-state colors. The simulator we use to draw these screens for the site had a lingering tint sitting on the accepted line until the capture showed there is none. What stays behind is the modification bar in the gutter and the unsaved dot on the tab, since accepting does not save the file for you. Source Control and that gutter bar are where to look if you want to see what moved after the fact.
How much any of this matters scales with who reads the diff after you. Alone in your own repo, an accepted hunk with two extra lines costs you a git checkout once you notice. Where that line goes into a pull request, the extra lines become somebody else's reading time, and the reviewer has no way to tell which of them you meant. Rejecting and asking again costs one more prompt. On a team with reviewers, reject and re-prompt.
How do I ask a quick question with inline edit?
The same prompt has a second mode: instead of editing the selection, it answers a question about it. Switch modes with a modifier on Enter, then ask. The table below shows the two keystrokes per platform.
- Action
- Open inline edit on a selection
- Mac
- ⌘K
- Windows / Linux
- CtrlK
- Action
- Switch to question mode
- Mac
- ⌥↵
- Windows / Linux
- ⌥↵
- Action
- Open Agent with the selection
- Mac
- ⌘L
- Windows / Linux
- CtrlL
| Action | Mac | Windows / Linux |
|---|---|---|
| Open inline edit on a selection | ⌘K | CtrlK |
| Switch to question mode | ⌥↵ | ⌥↵ |
| Open Agent with the selection | ⌘L | CtrlL |
Keystrokes as documented at cursor.com/help/ai-features/inline-edit.
Cursor's steps put the mode switch before you type, and in practice the order matters. Plain Enter submits your text as an instruction and applies an edit to the selection, so a question typed before the switch goes down the editing path. Switching first removes that possibility.
Once you are in question mode, type your question about the selected code. If the answer includes a change you want, you do not have to retype it as an instruction: type "do it" and press Enter, and Cursor applies the suggested change.
Question mode is probably the least-used part of inline edit, and the reason is fair enough, since Ask modeA read-only mode for asking questions about a codebase without changing files; the safe way to explore unfamiliar or legacy code. Press Enter for the full definition. is sitting in the side panel with room for a longer answer. What the inline version saves is the trip out of the file. The answer lands where you are already looking. For anything longer than a short explanation, the panel is still the better surface.
Can I switch from inline edit to Agent?
Yes, and the handoff keeps your selection. Inline edit is scoped to the code you highlighted; when a change needs to touch several files or reason across the codebase, that scope stops being useful. Select the code and press Cmd+L on Mac, or Ctrl+L on Windows and Linux. Agent opens with your selected code already attached as context, so you restate the task, not the location.
Both routes live on the same affordance. Select a line in Cursor 3An older release label for Cursor's multi-agent interface; current product guidance calls the active surface the Agents Window. Press Enter for the full definition..12 and the chip that appears on the selection offers Add to Chat `⌘L` and Quick Edit `⌘K` side by side.
The table further up gives the keystrokes and says nothing about what the second one costs. You are trading a change bounded by your selection for one that can reach files you have never opened, and everything Agent touches is something you then have to read.
The usual advice to plan before you execute does not carry across this line. Cursor puts Plan modeA mode that makes no edits: it researches the codebase and produces an editable plan you review before any code changes. Press Enter for the full definition. on complex features and on tasks that touch many files or systems, and its docs say outright that quick changes can go straight to Agent. A selection-sized edit is about as close to that description as a task gets. Inline edit is narrower again, and if the change does not fit inside what you highlighted, hand it over and read the diff on the other side.
Import your VS Code keymap and your two-step ⌘K shortcuts stop doing what they used to, because Cursor took the key for this feature and moved the keychord leader to ⌘R on Mac, CtrlM on Windows and Linux. The same key drives the prompt bar in the terminal, so a ⌘K that opens something other than the inline prompt usually means focus is in the terminal panel rather than the editor. The keybindings.json guide has the before-and-after mapping and the setting that hands the leader back.
Frequently asked questions
What is the keyboard shortcut for inline edit in Cursor?
Select the code, then press ⌘K on Mac or CtrlK on Windows and Linux. Type your instruction and press Enter to apply the edit to the selection.
Can inline edit answer a question instead of editing my code?
Yes. Open inline edit on a selection, then press ⌥↵ on Mac or ⌥↵ on Windows and Linux to switch to question mode. Ask your question; if you want to apply a change it suggests, type "do it" and press Enter.
Does inline edit change my code immediately?
No. The edit arrives as a pending proposal: the removed line renders red with the added line green beneath it, and the widget header shows Reject and Accept (⌘↵). Each hunk also has its own Undo and Keep buttons. Accepting clears the diff tints and leaves a gutter modification bar plus an unsaved dot on the tab, so you still save the file yourself.
When should I use Agent instead of inline edit?
Use Agent for multi-file edits or more complex changes. Select the code and press ⌘L (CtrlL on Windows and Linux) to open Agent with that selection as context.
Sources & last verified
Cursor ships frequently. Last updated July 28, 2026.