VS Code SetupBeginner

How to Use Copilot Chat and Inline Chat in VS Code

Ask questions in the Copilot chat sidebar and edit code in place with inline chat and slash commands.

8 minBeginner

Inline completions are only half of Copilot. The chat features let you ask about your code in plain language, request fixes, and make edits without leaving the editor. This guide covers the chat sidebar, inline chat, and the slash commands and references that make chat answers far more accurate.

What you need

  • GitHub Copilot and Copilot Chat installed and signed in
  • A project open in VS Code
  • About 6 minutes

Step 1: Open the chat sidebar

Click the chat icon in the Activity Bar or press Ctrl+Alt+I on Windows and Linux, or Cmd+Ctrl+I on macOS. Type a question and press Enter. The reply can include code blocks with buttons to copy them or insert them at your cursor.

VS Code - Copilot Chat
You
Why does this function return undefined?
Agent
Your function has no return statement after the loop. Add return result on the last line so the computed value is passed back to the caller.
A chat exchange in the Copilot sidebar.

Step 2: Use inline chat for in-place edits

Select a block of code and press Ctrl+I on Windows and Linux, or Cmd+I on macOS. A small chat box opens right over the selection. Describe the change you want, such as add input validation, and Copilot shows a diff you can accept or discard.

before and after (inline chat)
// before
function divide(a, b) {
  return a / b;
}

// after: "add a guard for division by zero"
function divide(a, b) {
  if (b === 0) throw new Error("Cannot divide by zero");
  return a / b;
}

Step 3: Use slash commands

Slash commands tell Copilot what kind of help you want. Type a forward slash at the start of a chat message to see the list. Common ones include /explain to walk through selected code, /fix to propose a correction, /tests to generate unit tests, and /doc to add documentation comments.

VS Code - slash commands
/explain Explain the selected code
/fix Propose a fix for a problem
/tests Generate unit tests
/doc Add documentation comments
Typing / reveals the available commands.

Step 4: Add context with references

Type the hash symbol in a chat message to attach context. Use #file to point at a specific file, #selection for the highlighted code, or #codebase to let Copilot search the whole workspace. Adding the right reference is the single biggest factor in getting a useful answer.

Be specific about scope
Instead of asking why is this broken, attach the failing file with #file and paste the error message. Copilot answers far better when it can see the exact code and symptom you are describing.

Example

Select a messy function, press the inline chat shortcut, and type rename variables for clarity and add comments. Copilot returns a cleaned-up version as a diff. You skim the change, click Accept, and the edit applies in place without copying anything by hand.

Watch related tutorials

Tags
#copilot#chat#ai#refactor