Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

VS Code GitHub Copilot

VS Code GitHub Copilot

GitHub Copilot is an AI coding assistant jointly developed by GitHub and OpenAI; it can automatically complete code based on context, generate functions, optimize logic, and even write entire code modules, helping developers code more efficiently.

GitHub Copilot is integrated into many IDEs such as VS Code, Visual Studio, and JetBrains, making you feel as if an experienced partner is always assisting you while you write code.


Core Features

Code auto-completion

GitHub Copilot can provide real-time code suggestions based on your code context and comments. It can:

Code explanation

Copilot can help you understand unfamiliar code:

Multi-Language Support

Supports almost all mainstream programming languages, including:


Installation and setup

Installation Steps

Prerequisites

Install the extension (older VS Code 1.115 and earlier versions)

Log in to your GitHub account

Enable GitHub Copilot

After installation, open VS Code's settings and search for Copilot; here we can adjust in VS Code settings:


Usage tips

Intelligent completion

When you start typing code, GitHub Copilot automatically gives suggestions, for example:

function fetchData(url) {

    // Copilot will automatically provide an implementation based on the fetch API

}

We can press the Tab key to accept a suggestion.

Generating code from comments

Simply write a comment, and Copilot will help you implement it:



# Implement a quicksort algorithm

Example

Implement a quicksort algorithm

def

quick_sort

(

arr

)

:

   

if

len

(

arr

)

<=

1

:

       

return

arr

    pivot

=

arr

[

len

(

arr

)

//

2

]

    left

=

[

x

for

x

in

arr

if

x

<

pivot

]

middle

=

[

x

for

x

in

arr

if

x

==

pivot

]

right

=

[

x

for

x

in

arr

if

x

pivot

]

return

quick_sort

(

left

)

(

right

)

You can even write a comment directly to have Copilot generate tests for you:

// 为 quicksort 函数生成单元测试

Also, we can right-click in the editor, select Copilot, and bring up the desired feature:

Keyboard shortcut descriptions:

Keyboard shortcut Description
Tab Accept suggestion
Esc Ignore suggestion
Ctrl + ] View next suggestion
Ctrl + [ View previous suggestion
Ctrl + Enter Open Copilot panel
Ctrl + Shift + P Enable/disable Copilot

Using the chat feature in VS Code

In Visual Studio Code, the chat feature lets you ask questions about the codebase in natural language or make multi-file edits in your project. The chat feature can run in different modes according to your needs, from asking questions and making multi-file edits to launching agentic coding workflows — it can meet all your needs.

You can use VS Code's chat feature in the following scenarios:

Tip: If you do not yet have a Copilot subscription, you can use Copilot for free by signing up for the Copilot Free plan, which has a monthly limit on completions and chat interactions.

Chat modes

Based on your specific needs, you can choose different chat modes:

Mode Description Scenario
Ask Ask questions about the codebase or technical concepts. Open in Stable or Preview. Understand how code snippets work, brainstorm software design ideas, or explore new technologies.
Edit (Edit) Perform multi-file edits in the codebase. Open in Stable or Preview. Apply code edits directly in the project to implement new features, fix bugs, or refactor code.
Agent (Agent) Launch an agentic coding workflow. Open in Stable or Preview. With minimal guidance, autonomously implement new features or advanced project requirements, invoke tools to perform specialized tasks, and iteratively resolve issues as they arise.

You can switch between different chat modes by using the mode dropdown menu in the chat view.