- Installing the Visual Studio Code extension
- Seeing your first suggestion
- Choosing alternate suggestions
- Getting more suggestions
- Generating code from a comment
- Using a framework
- More examples
- Keyboard shortcuts
- Enabling or disabling GitHub Copilot
- Learn More
To use GitHub Copilot, you first need to install the Visual Studio Code extension.
-
Visit the GitHub Copilot extension page on the Visual Studio Code Marketplace and install the extension.
-
Open Visual Studio Code. You will be prompted to authorize the extension by signing in to GitHub.
-
After you have authorized the extension, you will be returned back to Visual Studio Code.
If you receive the following message, you have not yet been added to the GitHub Copilot Technical Preview. The Technical Preview is open to a limited number of testers. To join the waitlist, visit copilot.github.com.
After installation, a GitHub Copilot icon should appear in the status-panel at the bottom of your Visual Studio Code window.
Having problems installing? Visit the Feedback forum.
GitHub Copilot provides suggestions for dozens of languages and a wide variety of frameworks, but it works especially well for Python, JavaScript, TypeScript, Ruby, and Go. The following samples are in JavaScript, but other languages will work similarly.
-
Create a new JavaScript (.js) file.
-
Type the following function header:
function calculateDaysBetweenDates(begin, end) {
-
GitHub Copilot will automatically suggest an entire function body in grayed text, as shown below. The exact suggestion may vary.
-
Press
Tab
to accept the suggestion.
GitHub Copilot will attempt to match your code's context and style. You can edit the suggested code as you choose.
For any given input, GitHub Copilot can provide multiple suggestions. As the developer you are always in charge; you can select which suggestion to use, or reject them all.
-
Clear the file (or start a new one), and type the following again:
function calculateDaysBetweenDates(begin, end) {
-
GitHub Copilot will again show you a suggested completion.
-
Instead of pressing
Tab
:- On macOS, press
Option (⌥) or Alt
+]
(orOption (⌥) or Alt
+[
). - On Windows or Linux, press
Alt
+]
(orAlt
+[
).
GitHub Copilot will cycle through other alternative suggestions.
- On macOS, press
-
When you see a suggestion you like, press
Tab
to accept it. -
If you don't like any of the suggestions, press
Esc
.
You can also hover over a suggestion to see the GitHub Copilot command palette for choosing suggestions.
Sometimes, you may not want to use any of the first set of suggestions. You can ask GitHub Copilot to return more.
-
Clear the file (or start a new one), and type the following again:
function calculateDaysBetweenDates(begin, end) {
-
GitHub Copilot will again show you a suggested completion.
-
Press
Ctrl
+Enter
. GitHub Copilot will open a new tab and suggest multiple options, as shown below. -
Pick a suggestion that you like, then click "Accept Solution" to continue.
-
If you don't like any of the returned suggestions, just close the suggestions tab.
GitHub Copilot can understand significantly more context than most code assistants, and can generate entire functions from something as simple as a comment.
-
Create a new JavaScript file, and type the following:
// find all images without alternate text // and give them a red border function process() {
-
GitHub Copilot will automatically suggest an implementation:
GitHub Copilot is especially useful for working with APIs and frameworks you're unfamiliar with. Here, we'll use GitHub Copilot to create a simple Express server that returns the current time.
-
Create a new JavaScript file, type the following comment, and then press
Enter
.// Express server on port 3000
-
GitHub Copilot will generate lines of code to create the Express app. Press
Tab
thenEnter
to accept each line. -
Type the following comment and press
Enter
.// Return the current time
-
GitHub Copilot will generate code for the default handler. Press
Tab
to accept each line.
GitHub Copilot can do even more. Check out the examples on copilot.github.com to see more, or the Gallery in this repository for the latest examples from us and the community.
Got an example of your own? We welcome you to share it on our Feedback forum.
The following lists the most common keyboard shortcuts relevant for GitHub Copilot. If you wish to rebind them, check out the configuration guide.
-
Accept an inline suggestion:
Tab
. -
Dismiss an inline suggestion:
Esc
. -
Show next inline suggestion:
Alt + ]
orOption (⌥) + ]
. -
Show previous inline suggestion:
Alt + [
orOption (⌥) + [
. -
Trigger inline suggestion:
Alt + \
orOption (⌥) + \
. -
Open Copilot (10 suggestions in separate pane):
Ctrl + Enter
.
The GitHub Copilot status icon in the bottom panel of the Visual Studio Code window indicates whether GitHub Copilot is enabled or disabled. Its background is blue when enabled, and red when disabled. To enable or disable GitHub Copilot, click the icon. You will be asked whether you wish to toggle for the current file type, or globally.
To learn more about configuring GitHub Copilot, go to the documentation table of contents.