Using GitHub Copilot

GitHub Copilot is a ChatGPT based AI pair programmer extension for Visual Studio Code, Visual Studio, JetBrains IDE, and Neovim. It is most effective in Python, JavaScript, TypeScript, Ruby, Go, C# and C++.

Installation

GitHub Copilot has personal and business subscription models. Start your free trial at https://github.com/features/copilot

Ask for suggestions

  • Create a file with the standard file extension of the language to indicate the preferred programming language to the AI.
  • Start to create a function with the name that describes its purpose (in this example we will use the JavaScript syntax)
    function getDaysInMonth(month, year) {
    (If your IDE automatically adds the closing curly brace, remove it, otherwise Copilot does not offer solutions)
    or
  • Create a comment to describe the functionality
    // Express server on port 3000 and return the current date

Select the suggestion

  • Use the Alt-[ and Alt-] on Windows, Option-[ and Otion-] on Mac to cycle through the suggested solutions and press Tab to accept it, or Esc to reject all of them.

See all suggestions in a new tab

  • Press Ctrl-Enter to open a new tab, and a few seconds later all suggestions will be listed in the new tab.
  • Click the Accept Solution link above the suggestion to insert it into your file.

For more information see the documentation

To activate and deactivate the GitHub Copilot

  • In the lower right corner of the editor click the Copilot icon
  • Select the scope to disable GitHub Copilot: for all languages, or for a specific language only.

Tutorials

There are GitHub repositories to learn to use GitHub Copilot. The Tutorials for GitHub Copilot page lists all of them. These are interactive repositories to learn the skills using real code:

  • skills-getting-started-with-github-copilot – The basics of using GitHub Copilot
  • skills-expand-your-team-with-copilot – How to use GitHub AI agents to do complex tasks in your repository

Interaction modes

GitHub Copilot has two main modes: Ask mode and Agent mode

Ask is an interactive communication mode, where the Copilot is a chat companion to give you information on the inner workings of the code, and give you brainstorming ideas.

Agent mode can make autonomous edits across multiple files in the project.

GitHub copilot Cheat Sheets

UI specific commands to enhance the work with Chat and Agent at GitHub Copilot Chat cheat sheet
The Visual Studio specific commands are:

Chat participants

Chat participants are like domain experts with specialty knowledge. Specify the chat participant with the @ symbol in your prompt. Most common chat participants are

VariableSpecialty
@azureAzure services
– Service deployment and management.
– App deployment to Azure.
@githubGitHub
– GitHub specific skills.
@terminalVisual Studio Code Terminal
– To create and debug Terminal commands
@vscodeVisual Studio Code
– Commands and features
@workspaceThe current workspace
– Project structure
– Code parts interaction
– Design patterns

For more information see Chat participants

Chat variables

Chat variables give specific context in the prompt. The chat variables are

VariableDescription
#blockIncludes the current block of code in the prompt.
#classIncludes the current class in the prompt.
#commentIncludes the current comment in the prompt.
#fileIncludes the current file’s content in the prompt.
#functionIncludes the current function or method in the prompt.
#lineIncludes the current line of code in the prompt.
#pathIncludes the file path in the prompt.
#projectIncludes the project context in the prompt.
#selectionIncludes the currently selected text in the prompt.
#symIncludes the current symbol in the prompt

For more information see Chat variables

Slash commands

Slash commands are frequently used instructions:

CommandDescription
/clearStart a new chat session.
/explainExplain how the code in your active editor works.
/fixPropose a fix for problems in the selected code.
/fixTestFailureFind and fix a failing test.
/helpQuick reference and basics of using GitHub Copilot.
/newCreate a new project.
/testsGenerate unit tests for the selected code.

For more visit Slash commands

Tools in chat

Type the # sign in the chat prompt to display the list of tools. The list contains the list of files referenced in the current chat, and the available tools.

For more about tools see Use tools in chat

MCP Servers

To enable the MCP gallery in the Visual Studio Code extension explorer

Some of the MCP server registries are

Starting MVP servers as Docker containers

When using Docker with stdio servers, don’t use the detach option (-d). The server must run in the foreground to communicate with VS Code.

For more on MCP Servers see Use MCP servers in VS Code

Inline Chat

Inline chat can help you with fast responses related to a particular line in the code. To invoke it move the cursor to the line and press Ctrl-I (Cmd-I on Mac), or right-click the line and select Copilot, Editor Inline Chat. If you want the AI to insert lines in to your code, like generating test data by adding elements to an array, place the cursor where the lines should go.

Leave a comment

Your email address will not be published. Required fields are marked *