Inline suggestions from GitHub Copilot in VS Code
AI agents: See llms.txt for documentation discovery and navigation. Documentation articles are also available as Markdown by appending .md to the article URL. Join VS Code at Microsoft Ignite or catch the sessions online. A year of VS Code, wrapped. Explore the highlights. Inline suggestions from GitHub Copilot in VS Code View as Markdown Ask in VS Code Ask in VS Code Insiders Use inline suggestions when you want to keep writing code yourself, with help completing code, comments, or tests and making related edits.
GitHub Copilot suggests changes in the editor as you type. You review each suggestion and decide whether to accept it, accept part of it, or keep typing. Copilot uses your existing code as context for two kinds of suggestions: Ghost text suggestions : Dimmed text at your cursor suggests how to complete the code you're writing. Next edit suggestions : Based on your recent edits, Copilot suggests another change and where to make it.
You don't need to start a chat for inline suggestions. You can also combine them with chat and agents as your task changes. Prerequisites Visual Studio Code installed on your machine. Follow these steps to set up VS Code . Access to a GitHub Copilot subscription. Follow these steps to set up GitHub Copilot . You can set up Copilot Free to get a monthly allowance of inline suggestions and AI credits. Ghost text suggestions Getting your first suggestions Copilot offers dimmed ghost text suggestions as you type: sometimes the completion of the current line, sometimes a whole new block of code.
Try completing a small JavaScript function in a temporary file. Suggestions vary, so check the behavior rather than expecting an exact implementation. Create and save a file named inline-suggestions-practice.js in a temporary folder. Add this comment and function stub: // Sum the numbers in the array. Return 0 for an empty array. function sumNumbers ( numbers ) {} Place the cursor after the opening { and press Enter to start a line inside the function.
Pause for a suggestion. If no suggestion appears, run Trigger Inline Suggestion from the Command Palette ( ⇧⌘P (Windows, Linux Ctrl+Shift+P ) ). If it still doesn't appear, check the inline suggestion troubleshooting steps . Review the suggested code. Press Tab to accept it, or Escape to dismiss it. To accept only part of a suggestion: Use ⌘→ (Windows, Linux Ctrl+Right ) to accept the next word. Run Accept Next Line Of Inline Suggestion from the Command Palette ( ⇧⌘P (Windows, Linux Ctrl+Shift+P ) ) to accept the next line.
When the function is complete, copy it and these calls into a browser's JavaScript console, or run them in your existing JavaScript runtime. Compare the output with the comments: console . log ( sumNumbers ([ 1 , 2 , 3 ])); // 6 console . log ( sumNumbers ([])); // 0 console . log ( sumNumbers ([- 2 , 5 ])); // 3 If a result differs, correct the code yourself or use inline chat to describe the failing case, then repeat the checks.
For changes to project code, run the relevant tests before relying on an accepted suggestion. Alternative suggestions For a given input, Copilot might offer more than one suggestion. Hover over the suggestion to see the toolbar, then use its next and previous controls to compare alternatives. Generate suggestions from code comments Instead of relying on Copilot to provide suggestions, you can provide hints about what code you expect by using code comments.
For example, you could specify a type of algorithm or concept to use (for example, "use recursion" or "use a singleton pattern"), or which methods and properties to add to a class. The following example shows how to instruct Copilot to create a class in TypeScript to represent a student, providing information about methods and properties: Next edit suggestions When one edit leads to another, next edit suggestions help you make the related changes.
For example, after you add a parameter to a function, Copilot can suggest updates to code that uses it. Suggestions can appear at your cursor or elsewhere in the file, and can change a symbol, a line, or several lines. To use next edit suggestions (Copilot NES), verify that github.copilot.nextEditSuggestions.enabled Open in VS Code Open in VS Code Insiders is enabled. Navigate and accept edit suggestions Press Tab to navigate to a suggested edit.
Review the proposed change, then press Tab again to accept it or Escape to dismiss it. An arrow in the gutter indicates if there is an edit suggestion available. The arrow indicates where the next edit suggestion is located, relative to your current cursor position. You can hover over the arrow to explore the edit suggestion menu, which includes keyboard shortcuts and settings configuration: Important If you are a VS Code vim extension user, please use the latest version of the extension to avoid any conflicts in keybindings with NES.
Reduce distractions by edit suggestions By default, edit suggestions are indicated by the gutter arrow and the code changes are shown in the editor. Enable editor.inlineSuggest.edits.showCollapsed Open in VS Code Open in VS Code Insiders to keep the suggested changes collapsed until you navigate to them. Alternatively, hover over the gutter arrow and select Show Collapsed from the menu. Use cases for next edit suggestions Catching and correcting mistakes Copilot helps with simple mistakes like typos.
It'll suggest fixes where letters are missing or swapped, like cont x = 5 or conts x = 5 , which should've been const x = 5 . Copilot can also help with more challenging mistakes in logic , like an inverted ternary expression: Or a comparison that should've used && instead of || : Changing intent Copilot suggests changes to the rest of your code that match a new change in intent. For example, when changing a class from Point to Point3D , Copilot will suggest to add a z variable to the class definition.
After accepting the change, Copilot NES next recommends adding z to the distance calculation: Refactoring Rename a variable once in a file, and Copilot will suggest to update it everywhere else. If you use a new name or naming pattern, Copilot suggests to update subsequent code similarly. Matching code style . After copy-pasting some code, Copilot will suggest how to adjust it to match the current code where the paste happened.
Enable or disable inline suggestions You can enable or disable inline suggestions either for all languages or for specific languages only. To enable or disable inline suggestions, select the Copilot menu in the Status Bar, and then check or uncheck the options to enable or disable inline suggestions. The option to disable inline suggestions for a specific language is dependent on the language of the active editor. Alternatively, modify the github.copilot.enable Open in VS Code Open in VS Code Insiders setting in the Settings editor.
Add an entry for each language you want to enable or disable inline suggestions for. To enable or disable inline suggestions for all languages, set the value for * to true or false . To temporarily disable all inline suggestions in the editor, select the Copilot menu in the Status Bar, and then select the Snooze button to increment the snooze time by five minutes. To resume inline suggestions, select the Cancel Snooze button in the Copilot menu.
Alternatively, use the Snooze Inline Suggestions and Cancel Snooze Inline Suggestions commands in the Command Palette. Use inline suggestions on metered connections When VS Code treats your network connection as metered, GitHub Copilot does not start new automatic ghost text or next edit suggestion requests. Requests already in progress continue. You can still request a suggestion explicitly. Run the Trigger Inline Suggestion command from the Command Palette.
This behavior applies only to the built-in Copilot provider. It does not change how local-only or third-party completion providers behave. Change the AI model for suggestions Different Large Language Models (L
The rest of this page is on the live site.