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.
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
