04-Code completions with GitHub Copilot in VS Code
04-Code completions with GitHub Copilot in VS Code
com/docs/copilot/ai-powered-suggestions
https://vscode.dev/github/microsoft/vscode-docs/blob/main/docs/copilot/ai-powered-suggestions.md)
• Code completions - Start typing in the editor, and Copilot provides code suggestions that match
your coding style and take your existing code into account.
• Next Edit Suggestions (preview) - Predict your next code edit with Copilot Next Edit Suggestions,
aka Copilot NES. Based on the edits you're making, Copilot NES both predicts the location of the
next edit you'll want to make and what that edit should be.
Getting started
Tip
If you don't yet have a Copilot subscription, you can use Copilot for free by signing up for the
Copilot Free plan (https://github.com/github-copilot/signup) and get a monthly limit of
completions and chat interactions.
3 Discover the key features of Copilot in VS Code with our Copilot Quickstart (/docs/copilot/getting-
started).
Inline suggestions
Copilot offers code suggestions as you type: sometimes the completion of the current line, sometimes a
whole new block of code. You can accept all, or part of a suggestion, or you can keep typing and ignore
the suggestions.
When you're presented with an inline suggestion, you can accept it with the Tab key.
Copilot tries to apply the same coding style for the code suggestions that you already have in your code.
Notice in the following example that Copilot applies the same input parameter naming scheme from the
add method for the suggested subtract method.
You might not want to accept an entire suggestion from GitHub Copilot. You can use the ⌘→ keyboard
shortcut to accept either the next word of a suggestion, or the next line.
Alternative suggestions
For any given input, Copilot might offer multiple, alternative suggestions. You can hover over the
suggestion to any of the other suggestions.
The following example shows how to instruct Copilot to create a class in TypeScript to represent a
student, providing information about methods and properties:
Inline suggestions are great at autocompleting a section of code. But since most coding activity is editing
existing code, it's a natural evolution of Copilot code completions to also help with edits, both at the
cursor and further away. Edits are often not made in isolation - there's a logical flow of what edits need to
be made in different scenarios. Copilot Next Edit Suggestions (Copilot NES) is this evolution.
Based on the edits you're making, Copilot NES both predicts the location of the next edit you'll want to
make and what that edit should be. Copilot NES helps you stay in the flow, suggesting future changes
relevant to your current work, and you can simply Tab to quickly navigate and accept Copilot's
suggestions. Suggestions may span a single symbol, an entire line, or multiple lines, depending on the
scope of the potential change.
Important
If you are a Copilot Business or Enterprise user, an administrator of your organization must opt in to
the use of Copilot Editor Preview Features, in addition to you setting
! (vscode://settings/
github.copilot.nextEditSuggestions.enabled)github.copilot.nextEditSuggestions.enabled
in your editor. Learn more about managing policies for Copilot in your organization (https://
docs.github.com/en/copilot/managing-copilot/managing-github-copilot-in-your-organization/
managing-policies-for-copilot-in-your-organization#enabling-copilot-features-in-your-organization).
An arrow in the gutter indicates if there is an edit suggestion available. You can hover over the arrow to
explore the edit suggestion menu, which includes keyboard shortcuts and settings configuration:
If an edit suggestion is below the current editor view, the arrow will point down instead of right:
• 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:
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.
! (vscode://settings/
• editor.inlineSuggest.edits.codeShifting)editor.inlineSuggest.edits.codeShifting
: disable this setting if you never want Copilot NES to shift your code when showing a suggestion.
! (vscode://settings/
• editor.inlineSuggest.edits.renderSideBySide)editor.inlineSuggest.edits.renderSideBySide
:
◦ auto (default): show larger edit suggestions side-by-side if there is enough space in the
viewport, otherwise the suggestions are shown below the relevant code.
◦ never: never show suggestions side-by-side, always show suggestions below the relevant
code.
Context
To give you relevant inline suggestions, Copilot looks at the current and open files in your editor to analyze
the context and create appropriate suggestions. Having related files open in VS Code while using Copilot
helps set this context and lets Copilot get a bigger picture of your project.
To enable completions:
1 Select Configure Code Completions... from the Copilot menu in the VS Code title bar.
To disable completions:
1 Select Configure Code Completions... from the Copilot menu in the VS Code title bar.
3 To disable completions for the language of the file you are currently editing, select Disable for
<language>.
1 Select Configure Code Completions... from the Copilot menu in the VS Code title bar.
2 Select Change Completions Model..., and then select one of the models.
Note
The list of available models might vary and change over time. If you are a Copilot Business or
Enterprise user, your Administrator needs to enable certain models for your organization by opting in
to Editor Preview Features in the Copilot policy settings (https://docs.github.com/en/enterprise-
cloud@latest/copilot/managing-copilot/managing-github-copilot-in-your-organization/managing-
policies-for-copilot-in-your-organization#enabling-copilot-features-in-your-organization) on
GitHub.com.
Settings
• ! (vscode://settings/editor.inlineSuggest.fontFamily)editor.inlineSuggest.fontFamily - configure
the font for the inline completions.
• ! (vscode://settings/editor.inlineSuggest.showToolbar)editor.inlineSuggest.showToolbar - enable
or disable the toolbar that appears for inline completions.
! (vscode://settings/
• editor.inlineSuggest.syntaxHighlightingEnabled)editor.inlineSuggest.syntaxHighlightingEnabled
- enable or disable syntax highlighting for inline completions.
! (vscode://settings/
• github.copilot.nextEditSuggestions.enabled)github.copilot.nextEditSuggestions.enabled
- enable Copilot Next Edit Suggestions (Copilot NES).
! (vscode://settings/
• editor.inlineSuggest.edits.codeShifting)editor.inlineSuggest.edits.codeShifting
- configure if Copilot NES is able to shift your code to show a suggestion.
! (vscode://settings/
• editor.inlineSuggest.edits.renderSideBySide)editor.inlineSuggest.edits.renderSideBySide
- configure if Copilot NES can show larger suggestions side-by-side if possible, or if Copilot NES
should always show larger suggestions below the relevant code.
Next steps
Yes No
02/06/2025
Follow @code(https://go.microsoft.com/fwlink/?LinkID=533687)
Request features(https://go.microsoft.com/fwlink/?LinkID=533482)
Report issues(https://www.github.com/Microsoft/vscode/issues)
Watch videos(https://www.youtube.com/channel/UCs5Y5_7XK8HLDX0SLNwkd3w)
(https://
www.microsoft.com)
(https://go.microsoft.com/fwlink/?LinkID=533687)
(https://github.com/microsoft/vscode) (https://www.youtube.com/@code)
Support (https://support.serviceshub.microsoft.com/supportforbusiness/create?sapId=d66407ed-3967-
b000-4cfb-2c318cad363d)
Privacy (https://go.microsoft.com/fwlink/?LinkId=521839)
Terms of Use (https://www.microsoft.com/legal/terms-of-use) License (/License)