Skip to content

Latest commit

 

History

History
193 lines (114 loc) · 7.59 KB

gettingstarted.md

File metadata and controls

193 lines (114 loc) · 7.59 KB

Getting Started with GitHub Copilot in Visual Studio

Prerequisites

1. Installing the Visual Studio extension

To use GitHub Copilot, you first need to install the Visual Studio extension.

  1. Open Visual Studio.

  2. In Extensions | Manage Extensions, from the Visual Studio Marketplace, install the GitHub Copilot extension for Visual Studio.

Manage Extensions

  1. Close the dialog, then exit and relaunch Visual studio.

Manage Extensions restart

  1. After restarting Visual Studio, use Extensions | Manage Extensions | Installed to confirm that the GitHub Copilot extension is installed and enabled.

Manage extensions confirmmation

Having problems installing? Visit the Feedback forum.

2. Seeing your first suggestion

GitHub Copilot provides suggestions for dozens of languages and a wide variety of frameworks, but it works especially well for Python, JavaScript, TypeScript, Ruby, Go, C#, and C++. The following samples are in C#, but other languages will work similarly.

  1. Create a new C# Console App project by following the instructions in steps 1 and 2 here.

  2. Name your project "Copilot Demo".

Configure your new project

  1. Click "Next".

Additional information

  1. Click "Create".

    1. The very first run, you will be presented with a message to activate your connection to GitHub

First run authorization

  1. A device code will be copied automatically to the clipboard. Paste it on the GitHub device authorization page that will open. If you miss the device code, you will find it in the status bar, at the bottom left of Visual Studio, as well as on the GitHub Copilot output window pane.

First run device code First run device code output

  1. After successful authorization, proceed to read and approve the telemetry terms.

First run telemetry consent

After installation, a GitHub Copilot icon should appear in the editor margin at the bottom of your Visual Studio window, in the lower left.

icon

and your file should show short "Hello, World!" code.

Hello, world!

  1. Below that, type the following function header:

    int CalculateDaysBetweenDates(
    
  2. GitHub Copilot will automatically suggest an entire function body in grayed text, as shown below. The exact suggestion may vary.

    Code suggested by GitHub Copilot

  3. 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.

3. Choosing alternate suggestions

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.

  1. Clear the file (or start a new one), and type the following again:

    int CalculateDaysBetweenDates(
    
  2. GitHub Copilot will again show you a suggested completion.

  3. Instead of pressing Tab, press Alt+. (or Alt+,).

    GitHub Copilot will cycle through other alternative suggestions.

Alternate code suggested by GitHub Copilot

  1. When you see a suggestion you like, press Tab to accept it.

  2. 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.

Code suggested by GitHub Copilot

4. Generating code from a comment

GitHub Copilot can understand significantly more context than most code assistants, and can generate entire functions from something as simple as a comment.

  1. Clear the file (or start a new one), and type the following:

    using System.Xml.Linq;
    
    var doc = XDocument.Load("index.xhml");
    
    // find all images

    Press Enter.

  2. GitHub Copilot will automatically suggest an implementation. Press "tab" to accept it.

  3. Enter a second comment

    // and give them a red border

    Code from comment

6. More examples

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.

7. Keyboard shortcuts

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 + ..

  • Show previous inline suggestion: Alt + ,.

  • Trigger inline suggestion: Ctrl + Alt + \.

8. Enabling and disabling GitHub Copilot

The GitHub Copilot status icon in the bottom panel of the Visual Studio window indicates whether GitHub Copilot is enabled or disabled. It will have a diagonal line through it when disabled. To enable or disable GitHub Copilot, click the icon. You will be asked whether you wish to toggle for the current file, current file type, or globally.

icon

9. Learn More

To learn more about configuring GitHub Copilot, go to the documentation table of contents.