Cursor

Verified against Cursor · 2026-06-25

Get a contained edit out of Cursor Cmd+K instead of a rewritten block

A Cmd+K inline-edit instruction that names the transformation and exactly what must stay byte-identical, tuned for the selection-scoped inline editor rather than a whole-file agent pass.

Cursor 2.1

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]

Transform only the selected code. Do not touch anything outside the highlight, and do not restyle lines inside it that the transformation 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) around the fetch call.

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

Keep the existing function/variable names and the surrounding formatting style unless the transformation explicitly requires changing one of them. If the transformation can't be done without changing something in MUST STAY BYTE-IDENTICAL, stop and explain why instead of doing it anyway.
Customize the highlighted detailsoptional — the prompt above already works

Why this works

Cmd+K's diff preview is scoped to the highlighted selection and its immediate surrounding context, which is a narrower window than Composer's full-repo index — that narrowness is the feature, but it also means Cmd+K has less context to infer what not to change, so it will happily reformat the whole block while it's in there rewriting one line. Restating 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. Naming a MUST STAY BYTE-IDENTICAL list is the actual lever: it converts an implicit expectation ('obviously keep the signature the same') into a checkable constraint, which matters specifically for Cmd+K because its regeneration of the selected block is a full rewrite of that span, not a patch — nothing stops it from returning a differently-shaped block unless told what to preserve.

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 unchanged, as required.

Verified against

Cursor 2.1 · 2026-06-25

Changelog

  • 2026-06-25 Initial publish, verified against Cursor 2.1 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
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