Topic 1 of 5 · 4 min read
Inline edits and next-edit suggestions
Goal: Use an inline edit for a scoped change and judge from its diff whether to accept, refine or reject it.
An inline edit is a small, scoped change you can read in seconds: select the code, say what should change, and judge the diff before you accept it. Treat it as a fast pair partner for one function, not as a way to rewrite a file.
Check yourself · 1 of 3
What should an inline edit selection be?
Why it matters
Inline edits (Copilot inline chat, Cursor's edit shortcut, JetBrains AI Assistant's in-editor prompt) are the lowest-risk way to use an AI tool. The change lands next to your cursor, shows as a diff and can be undone at once. That safety only holds if the change stays small. A model that is told "clean this up" may reformat a whole file, rename things and drop a comment you needed. Next-edit suggestions add a second habit: the editor predicts your next change and offers it with one key press. It is easy to tab through five suggestions without reading any of them.
How to do it
- Select exactly the code to change. The selection is the boundary. Lines outside it should not move.
- Write the change as one instruction with a constraint. Name the input, the output and what must stay the same.
- Read the diff before you accept. Look at removed lines first: a deleted check or comment is the usual silent loss.
- Accept, refine or reject. If it is close, say what is wrong and run it again on the same selection. If it is far off, reject and rewrite the instruction instead of patching a bad result.
- Read each next-edit suggestion as a diff. Accept it only when you can say why the edit follows from your last change, for example renaming a parameter and updating its uses.
Before and after
Weak: select a whole 200-line service file and type "make this better". The result touches 60 lines and you cannot review it.
Better: select one function and type "Return early when items is empty. Do not change the signature or the error handling."
function total(items: Item[]): number {
+ if (items.length === 0) return 0;
return items.reduce((sum, i) => sum + i.price * i.qty, 0);
}
The diff has one added line, so you can verify it by eye.
What goes wrong
- Selections that are too wide. The more lines the model can touch, the more it changes that you did not ask for.
- Tab-through acceptance. Predicted edits look plausible, and plausible edits are exactly the ones that slip through unread.
- Silent removals. The model tidies a function and drops a null check, a log line or a comment that explained a workaround.
- Accepting twice. If you accept, edit by hand and accept again, the result may mix two versions. Save a clean state first.
Examples
Scoped instruction with a constraint
You select the parseAmount function and type: "Accept a trailing currency symbol such as $ or EUR. Keep the return type and keep throwing ParseError on bad input." The diff adds one regex and one branch. You check the error path is untouched and accept.
Tab-through trap
You rename userId to accountId in one file. The editor suggests the next edit in five places. Four are renames. The fifth also changes if (!accountId) return to if (accountId == null) return, which now lets an empty string through. Reading each suggestion as a diff catches it.
Key points
- The selection is the boundary: select only the code you want changed.
- A good inline instruction names the change and what must stay the same.
- Read removed lines in the diff first, because silent deletions are the common loss.
- Accept a next-edit suggestion only when you can explain why it follows from your last edit.
- If a result is far off, reject it and rewrite the instruction instead of patching it.
Common mistakes
- Selecting a whole file and asking for general improvement.
- Accepting a series of predicted edits without reading each one.
- Looking only at added lines and missing a deleted guard or comment.
- Re-prompting on top of a bad result instead of rejecting it and starting clean.
Check yourself · 2 of 3
You asked an inline edit to add logging. The diff shows 3 added lines and 1 removed line. Which line deserves the closest look?
Check yourself · 3 of 3
The editor offers five predicted next edits after you rename a parameter. What is the best habit?
Practice items, not counted towards your mastery.
Start here
- Build with AI in VS Code (opens in a new tab)DocsFree
An overview of inline suggestions, chat and agents in one editor, with the controls for each.
- Add context to chat (VS Code docs) (opens in a new tab)DocsFree
How to attach files, symbols and other context so the agent answers from the right code.
- Review AI code edits (VS Code docs) (opens in a new tab)DocsFree
Keep and undo controls, and what restoring a chat checkpoint does and does not undo.