Cursor

Verified against Cursor · 2026-07-22

Force Cmd+K to change only the highlighted lines, not the whole block around them

A Cmd+K inline-edit instruction that states the transformation, an explicit byte-identical preserve list, and a fallback rule for when the transformation can't be done cleanly, tuned for the selection-scoped inline editor rather than a whole-file Agent pass.

Cursor 2.24 fillable variables

The prompt

Ready to copy — highlighted parts are example details you can swap.

[Cmd+K on the selected block — this instruction applies only to the highlighted selection, not the surrounding file]

Transform only the selected code. Do not touch anything outside the highlight, and do not restyle, reindent, or rename anything inside it that the transformation itself doesn't require changing.

WHAT THE SELECTED CODE CURRENTLY DOES
This function fetches a user by id and returns null if the id is missing or the fetch fails.

TRANSFORMATION
Add retry with exponential backoff (max 3 attempts, base delay 100ms) around the fetch call.

MUST STAY BYTE-IDENTICAL
The function signature getUser(id: string): Promise<User | null> and its null-on-missing-id behavior.

CALLERS THAT DEPEND ON THIS BLOCK
Called from three places: UserProfile.tsx checks for null to show a "not found" state, AdminPanel.tsx awaits it in a Promise.all with two other fetches, and a background job retries the whole call on any thrown error already.

RULES
- Keep existing function and variable names, parameter order, and the surrounding formatting style unless the transformation explicitly requires changing one of them.
- If the transformation genuinely cannot be done without changing something listed under MUST STAY BYTE-IDENTICAL, stop and explain exactly why in one or two sentences instead of doing it anyway and hoping it goes unnoticed in review.
- If you need information about what's outside the selection to do this correctly — a type definition, an import, a sibling function's signature — say what you need rather than guessing at its shape and writing code that assumes it.
- Do not add error handling, logging, or comments beyond what the transformation itself calls for. A larger, more "complete" version of the block than what was asked for is still an out-of-scope change.

After the edit, state in one line whether every item under MUST STAY BYTE-IDENTICAL actually held, or name the one that didn't and why it was unavoidable.

Customize

Optional — swap in your own details for the highlighted parts above.

Why this works

Cmd+K's diff preview is scoped to the highlighted selection and a narrow band of surrounding context, which is a much smaller window than Agent mode's full-repo index — that narrowness is the whole point of using Cmd+K instead of Agent mode for a small change, but it also means Cmd+K's regeneration of the block is a full rewrite of that span, not a line-level patch, so nothing stops it from reformatting the entire selection while it's in there changing one thing unless it's told not to. Stating what the selected code currently does anchors intent for an editor that isn't reasoning over the rest of the file the way an Agent-mode pass would; without that anchor, a transformation instruction like "add retry" has no stated baseline behavior to preserve against, only the code's shape to infer it from. The MUST_STAY_BYTE_IDENTICAL list is the actual lever: it converts an implicit expectation — "obviously keep the signature the same" — into something checkable, which matters specifically for Cmd+K because a rewritten block that happens to change a return type or drop the null-check branch will still look plausible in the diff preview unless the reviewer is checking against a stated list rather than a general impression of "looks right." CALLERS_CONTEXT closes a gap that's easy to miss precisely because Cmd+K's view is deliberately narrow: the model regenerating the selected function has no visibility into how its return value gets consumed three files away unless told, so a change that looks internally consistent — say, throwing instead of returning null on failure — can silently break a caller that was written assuming the old contract, and Cmd+K's scoped diff view will never surface that break because the caller file isn't part of what's being shown.

What you get back

async function getUser(id: string): Promise<User | null> { if (!id) return null for (let attempt = 0; attempt < 3; attempt++) { try { return await fetchUser(id) } catch (err) { if (attempt === 2) throw err await sleep(2 ** attempt * 100) } } return null } // Signature and null-on-missing-id behavior held unchanged, as required. // Note: caller AdminPanel.tsx uses Promise.all — a thrown error here after 3 failed // attempts will now reject the whole Promise.all, same as its existing background-job // retry path already assumed, so no caller behavior changes.

Verified against

Cursor 2.2 · 2026-07-22

Changelog

  • 2026-07-22 Initial publish, verified against Cursor 2.2 Cmd+K inline edit.

Need this built into your business?

If a prompt isn't enough — custom software, built and maintained for you — that's Scult's day job.

EXPLORE CUSTOM SOFTWARE
Brief Cursor's Agent mode to build a multi-file feature without wandering into untouched filesA Composer/Agent-mode brief that names the files in scope, the data contract between them, the codebase's existing conventions, and what to leave alone, plus a forced pre-edit plan, so an autonomous multi-file build stays inside the feature you actually asked for instead of expanding into whatever the semantic index surfaces as related.Cursor 2.22026-08-05Point Cursor BugBot at the actual risk in a PR instead of a generic pass over the diffA PR description written for BugBot, Cursor's automated PR-review agent, that states risk areas and known trade-offs up front and defines exactly how findings must be classified and cited, so its comment thread concentrates on real logic and security risk instead of restating the diff or re-litigating a deliberate choice.Cursor BugBotCursor 2.22026-07-30Write a Background Agent brief that survives running with nobody watchingA self-contained task brief for Cursor's Background Agents — the async, remote-run agent mode — with success criteria, a conservative-default policy for ambiguity, and a reviewable-PR requirement, since no one answers follow-up questions while it works in an isolated container.Cursor Background AgentsCursor 2.22026-08-02Turn Cursor's Agent-mode checkpoints into a real rollback plan for a risky refactorA refactor brief that breaks a risky change into checkpoint-sized steps and tells the agent to stop and name the last good checkpoint on failure — instead of patching a bad step with a second speculative fix — plus a named rollback trigger phrase for mid-session use.Cursor 2.22026-08-06
All Cursor prompts

Check your AI visibility

One URL in, a 0–100 score and the exact fixes out.

RUN THE CHECK

Browse all the tools

15 tools across six categories
13 of them never send your data anywhere

Free · No signup · No trial clock

SEE THE DIRECTORY