Learn › GitHub Copilot Mastery › Edit Mode: Targeted Refactors Across Multiple Files

Edit Mode: Targeted Refactors Across Multiple Files

Intermediate 🕐 12 min Lesson 5 of 13
What you'll learn
  • Open Copilot Chat in Edit mode and describe a targeted code change across one or more files
  • Review an Edit mode diff and accept or reject individual changes before applying them
  • Choose between Edit mode and Agent mode based on the scope and nature of the task

Describing Changes Instead of Writing Them

Edit mode is the middle ground between Ask mode (read-only conversation) and Agent mode (fully autonomous execution). In Edit mode, you describe a change you want to make, and Copilot proposes exactly how to make it — showing you a diff across all the affected files before anything is written. You review, accept or reject each change, and apply what you approve.

This is the right mode when you know what you want to change but writing it manually would be tedious. Renaming a concept across ten files, converting a callback-style API to async/await, adding error handling to a set of functions, updating a data structure and all the places it is used — these are Edit mode tasks.

Starting an Edit Session

In VS Code, switch to Edit mode using the mode dropdown at the top of the Copilot Chat panel. You can also open an inline edit with Ctrl+I directly in the editor, which scopes the edit to your current selection or the surrounding function.

For a multi-file edit, open Chat, switch to Edit mode, then add the files you want to change using the Add Files button or by typing #file:filename. Describe what you want to change in plain English. Copilot reads all the referenced files, plans the changes, and presents the diff.

Reviewing the Diff

Edit mode shows proposed changes inline in each file, highlighted as additions and deletions. You see exactly what will change before it changes. Navigate between changed files using the arrows in the Chat panel. For each file, you can:

  • Accept all — Apply all proposed changes to this file
  • Discard — Reject the proposed changes for this file
  • Accept individual hunks — Hover over a specific block of changes and accept just that portion

If you accept the changes and then decide you do not like the result, standard undo (Ctrl+Z / Cmd+Z) reverts each accepted change. Edit mode integrates with VS Code's undo stack.

Good Edit Mode Prompts

The quality of the edit depends heavily on how you describe the change. Effective prompts are specific about what to change and what constraints to respect:

  • Vague: "Make this better"
  • Specific: "Refactor these functions to use async/await instead of .then() chains. Do not change any error handling logic."
  • Vague: "Add types"
  • Specific: "Add TypeScript types to all function parameters and return values in these files. Use the existing User and Order types from types.ts."

Constraints are just as important as the description. If there are things you don't want changed — specific functions, existing behaviour, naming conventions — state them explicitly.

Edit Mode vs Agent Mode

Edit mode
Agent mode
You specify which files to include
Agent determines which files to change on its own
Changes are shown as a diff for you to review before applying
Agent applies changes and can run terminal commands
No terminal commands run
Can run npm install, run tests, fix errors, iterate
Best for targeted, well-scoped refactors
Best for multi-step tasks with unknowns

Try This

Find a function in your codebase that does not have error handling — no try/catch, no null checks. Open Copilot Chat in Edit mode, add the file as context, and prompt: "Add proper error handling to this function. Throw descriptive errors for invalid input and catch any async failures." Review the diff, accept the changes you agree with, and reject anything you'd handle differently.

Key takeaways
  • Edit mode shows a diff of all proposed changes before writing anything — you review and approve each file's changes
  • Effective Edit mode prompts include both what to change AND explicit constraints about what not to change
  • Edit mode does not run terminal commands; Agent mode does — use Edit for scoped refactors where you know exactly what needs to change