skip to content

In Cursor, when should a selected function be changed with inline edit (Cmd/Ctrl+K) rather than sent to Agent with Cmd/Ctrl+L?

level: juniorimportance: must knowfreq 18%

answer

  1. the change's reach decides
  2. selection in, edit in place
  3. Return applies, a follow-up refines
  4. Cmd/Ctrl+L opens Agent with the selection
  5. multi-file or complex work goes to Agent

basics

~20 s

Use Cursor's inline edit (Cmd/Ctrl+K) when the change belongs to the selection: one instruction, applied in place, refined by follow-ups. Use Cmd/Ctrl+L when it spans files or needs exploring, so Agent starts with the selection as context.

solid answer

~40 s

Cursor's **inline edit** is the targeted surface: select code, press `Cmd+K` (`Ctrl+K` on Windows/Linux), type an instruction such as "Convert this to an async function" and press Return; Cursor applies the edit to the selected code without opening the chat panel, and another instruction plus Return refines the same edit. When the change will not stay inside the selection — callers in other files, a multi-file refactor, anything that needs searching or running commands — select the code and press `Cmd+L` (`Ctrl+L`) instead: that opens **Agent** with the selection as context, and Agent searches the codebase, edits several files and runs terminal commands on its own. The decision is about the reach of the change, not its difficulty.

go deeper

for a junior

Recall the two keys: Cmd/Ctrl+K edits the selected code in place from one instruction, and Cmd/Ctrl+L opens Agent with the selection as context. Know that a follow-up instruction refines an inline edit.

for a middle

Explain the boundary in terms of reach: inline edit acts on the selection, Agent searches, edits several files and runs commands. Mention Cmd+L versus Cmd+Shift+L for a new or an existing chat.

for a senior

Show judgement about the ripple: an async conversion done with Cmd+K leaves the callers to you. Note that rules reach Agent but not inline edit, which matters when conventions must hold.

for a principal

Frame the choice as review cost: a one-selection change is cheap to verify, a multi-file Agent run is not. Guide a team on when each surface keeps diffs small enough to review well.

## Two surfaces for one selection Cursor gives a developer two ways to act on code they have just selected. **Inline edit** (`Cmd+K` on Mac, `Ctrl+K` on Windows/Linux) works on the selection itself. **Agent**, opened with the selection by `Cmd+L` (`Ctrl+L`), is Cursor's assistant that "searches your codebase, edits multiple files, runs terminal commands, and fixes errors on its own". Both start from the same highlighted function; they differ in how far the result is allowed to travel. | | Inline edit (`Cmd/Ctrl+K`) | Agent via `Cmd/Ctrl+L` | |---|---|---| | Where you type | A prompt on the selection, in the editor | The Agent side panel | | What it changes | The selected code, in place | Whatever files the task needs | | Other tools | None described on the help page | Codebase search, file edits, terminal commands, web | | Iterating | A follow-up instruction plus Return | Further chat messages | | Best for | Quick, targeted changes | Multi-file edits or more complex changes | ## How an inline edit runs Cursor's help page describes the flow in five steps: 1. Select the code you want to change. 2. Press `Cmd+K` on Mac or `Ctrl+K` on Windows/Linux. 3. Type the instruction, for example "Convert this to an async function." 4. Press Return; Cursor applies the edit to the selected code. 5. To refine, add a follow-up instruction and press Return again. The point of step 5 is that you do not throw a near-miss away. If the async conversion used the wrong error type, the next instruction ("keep throwing `IOException`") refines the same edit rather than starting over. The same prompt also has a question mode (`Opt+Return` on Mac, `Alt+Return` on Windows/Linux) for asking about the selection instead of changing it. ## When the change outgrows the selection The help page draws the line itself: "For multi-file edits or more complex changes, select code and press Cmd + L on Mac (Ctrl + L on Windows/Linux). This opens Agent with your selected code as context." Typical signs that you have crossed it: - making a function `async` means every caller must now `await` it, and the callers live in other files; - the instruction starts with "find" or "everywhere" — inline edit acts on what you selected, Agent searches; - the change needs a command run to confirm it, such as a test or a build; - you want Agent's working style for the job: its mode picker (Ask, Plan, Debug) and its project rules apply there. The keyboard reference adds a nuance worth knowing: with code selected, `Cmd+L` is "Add selection to new chat", while `Cmd+Shift+L` is "Add selection to Chat", attaching it to the conversation already open. Use the first to start a fresh task from the selection and the second when the selection is extra evidence for a task Agent is already doing. ## The divergence scenario: one function, nothing else A developer wants a single function converted to async and explicitly does not want any other file touched. That is inline edit's job: select the function, `Cmd+K`, state the conversion, Return, and review the result in place. The trade-off is that the developer, not the tool, now owns the ripple — any caller that needs an `await` is theirs to find. If the developer actually wants the callers updated too, the honest choice is `Cmd+L`, letting Agent find and edit them, and reviewing a multi-file diff instead of a one-function change. ## What does not change between the two Some controls apply to both surfaces, so the choice is not a security decision: - files listed in `.cursorignore` are blocked from inline edit as well as from Agent and Tab; - the hooks page lists its Agent hooks as applying to Cmd+K as well as Agent Chat operations. One thing does differ: the rules system (project, team and user rules) is applied in Agent's conversations, not to inline edit — a team that relies on rules for conventions should know which surface they reach. ## Common mistakes - Treating `Cmd+K` as "small Agent": it does not go searching other files for you. - Repeating a whole `Cmd+K` from scratch instead of refining it with a follow-up instruction. - Expecting `Cmd+L` to apply an edit straight away: it hands the selection to Agent as context, and Agent decides what to edit. - Splitting a genuine multi-file change into a string of single-selection edits, losing the search that finds the places you forgot.

  • In Cursor, what is the difference between Cmd+L and Cmd+Shift+L with code selected?
    Cursor's keyboard reference lists `Cmd+L` as "Add selection to new chat" — it opens Agent with the selection as context for a fresh task. `Cmd+Shift+L` is "Add selection to Chat": it attaches the selection to the conversation already open, which suits giving Agent extra evidence mid-task. Both keys are remappable in Keyboard Shortcuts.
  • An inline edit result in Cursor is nearly right. Do you cancel and start again?
    No. Cursor's documented flow is to add a follow-up instruction to the same inline edit and press Return again; the edit is refined rather than redone. Starting over discards the part that was already right and usually costs another round of review.
  • Does sending a selection to Agent with Cmd/Ctrl+L change which conventions are applied?
    Yes. Cursor applies project, team and user rules in Agent's conversations (Agent, Ask, Plan and Debug modes), but its rules documentation says rules do not apply to inline edit. A change that must follow written team conventions reaches them through Agent; with `Cmd+K` the conventions have to be in the instruction itself.

  • Cmd+K hands the selection to Agent, which may then edit other files.
  • Cursor's inline edit only works from inside the chat panel.
  • Cmd+L applies the edit directly to the selection, just like Cmd+K.
  • To refine an inline edit you must cancel it and write a new one.
  • Cmd+L and Cmd+Shift+L both open a new Agent chat with the selection.