Skip to main content

Getting code suggestions in your IDE with GitHub Copilot

Use GitHub Copilot to get code suggestions in your editor.

About GitHub Copilot and JetBrains IDEs

This guide demonstrates how to get coding suggestions from GitHub Copilot in a JetBrains IDE. To see instructions for other popular coding environments, use the tool switcher at the top of the page.

The examples in this guide use Java, however other languages will work similarly. GitHub Copilot 为多种语言和各种框架提供建议,但尤其适用于 Python、JavaScript、TypeScript、Ruby、Go、C# 和 C++。 GitHub Copilot 还可以帮助生成数据库的查询,生成 API 和框架的建议,并可以帮助开发基础结构即代码。

Prerequisites

  • Access to Copilot. To use GitHub Copilot in JetBrains, you need either limited access through Copilot 免费版 or a paid Copilot plan for full access. 有关如何访问 Copilot 的信息,请参阅“What is GitHub Copilot?”。

  • Compatible JetBrains IDE. To use GitHub Copilot in JetBrains, you must have a compatible JetBrains IDE installed. GitHub Copilot is compatible with the following IDEs:

    • IntelliJ IDEA(旗舰版、社区版、教育版)
    • Android Studio
    • AppCode
    • CLion
    • Code With Me Guest
    • DataGrip
    • DataSpell
    • GoLand
    • JetBrains Client
    • MPS
    • PhpStorm
    • PyCharm(专业版、社区版、教育版)
    • Rider
    • RubyMine
    • RustRover
    • WebStorm
    • Writerside

    请参阅 JetBrains IDE 工具查找器进行下载。

  • GitHub Copilot**** 插件。 请参阅 JetBrains Marketplace 中的 GitHub Copilot 插件。 有关安装说明,请参阅“Installing the GitHub Copilot extension in your environment”。

  • 在 JetBrains IDE 中登录到 GitHub。 有关身份验证说明,请参阅“Installing the GitHub Copilot extension in your environment”。

Getting code suggestions

GitHub Copilot offers coding suggestions as you type. For example, in a Java file, create a class by typing class Test.

GitHub Copilot will automatically suggest a class body in grayed text. 要接受建议,请按 Tab

You can also describe something you want to do using natural language within a comment, and Copilot will suggest the code to accomplish your goal. For example, type this comment in a Java file:

Java
// find all images without alternate text
// and give them a red border
void process () {

GitHub Copilot will automatically suggest code. 要接受建议,请按 Tab

GitHub Copilot will attempt to match the context and style of your code. You can always edit the suggested code.

提示

If you receive limited or no suggestions from Copilot, you may have duplication detection enabled. For more information about duplication detection, see Managing Copilot policies as an individual subscriber.

Showing alternative suggestions

对于任何给定的输入,GitHub Copilot 可以提供多个建议。 可以选择要使用的建议,或拒绝所有建议。

For example, type the following line in a Java file, and press Enter:

Java
private int calculateDaysBetweenDates(Date date1,

GitHub Copilot will show you a suggestion.

Now hover over the suggestion to show the GitHub Copilot control for choosing suggestions. To display next or previous suggestions, click the forward or back arrow button in the control.

You can also use keyboard shortcuts to show alternative suggestions:

OSSee next suggestionSee previous suggestion
macOSOption+]Option+[
Windows or LinuxAlt+]Alt+[

要接受建议,请单击 Copilot 命令面板中的“接受”,或按 Tab。要拒绝所有建议,请按 Esc

Showing multiple suggestions in a new tab

如果不想使用 GitHub Copilot 提供的任何初始建议,可以在新选项卡中显示多个建议。

For example, type the following line in a Java file:

Java
private int calculateDaysBetweenDates(Date date1,

GitHub Copilot will show you a suggestion.

To open a new tab with multiple additional suggestions, use the following keyboard shortcut, then click Open GitHub Copilot:

OSOpen multiple suggestions
macOSCommand+Shift+A
Windows or LinuxCtrl+Enter

To accept a suggestion, below the suggestion, click Accept suggestion NUMBER. To reject all suggestions, close the tab.

Accepting partial suggestions

If you don't want to accept an entire suggestion from GitHub Copilot, you can accept the next word or the next line of a suggestion.

For example, type the following line in a Java file:

Java
private int calculateDaysBetweenDates(Date date1,

GitHub Copilot will show a suggestion in grayed text. The exact suggestion may vary.

Now hover over the suggestion to show the GitHub Copilot control for choosing suggestions. To accept only the next word of the suggestion, click Accept Word in the control.

Alternatively, you can use a keyboard shortcut to accept the next word of a suggestion:

OSAccept Next WordAccept Next Line
macOSCommand+Command+Control+
Windows or LinuxControl+Control+Alt+

If you want to accept the next line of a suggestion, you will need to set a custom keyboard shortcut for the command editor.action.inlineSuggest.acceptNextLine. For more information on setting custom keyboard shortcuts, see Configuring GitHub Copilot in your environment.

About GitHub Copilot and Visual Studio

This guide demonstrates how to get coding suggestions from GitHub Copilot in Visual Studio for Windows. To see instructions for other popular coding environments, use the tool switcher at the top of the page.

The examples in this guide use C#, however other languages will work similarly. GitHub Copilot 为多种语言和各种框架提供建议,但尤其适用于 Python、JavaScript、TypeScript、Ruby、Go、C# 和 C++。 GitHub Copilot 还可以帮助生成数据库的查询,生成 API 和框架的建议,并可以帮助开发基础结构即代码。

Prerequisites

  • Access to Copilot. To use GitHub Copilot in GitHub Copilot in Visual Studio, you need either limited access through Copilot 免费版 or a paid Copilot plan for full access. 有关如何访问 Copilot 的信息,请参阅“What is GitHub Copilot?”。

  • Visual Studio 的兼容版本。 要在 Visual Studio 中使用 GitHub Copilot,必须安装 Visual Studio for Windows 版本 2022 17.8 或更高版本。 有关更多信息,请参阅 Microsoft 文档中的“安装 Visual Studio”。

  • 适用于 Visual Studio 的 GitHub Copilot 扩展。 有关如何安装 Copilot 扩展的说明,请参阅 Microsoft 文档中的“在 Visual Studio 中安装 GitHub Copilot”。

  • 将 GitHub 帐户添加到 Visual Studio。 请参阅 Microsoft 文档中的将 GitHub 帐户添加到 Visual Studio 密钥链

Getting code suggestions

GitHub Copilot offers coding suggestions as you type. For example, type this function signature in a C# file:

C#
int CalculateDaysBetweenDates(

GitHub Copilot will automatically suggest an entire function body in grayed text. 要接受建议,请按 Tab

You can also describe something you want to do using natural language within a comment, and Copilot will suggest the code to accomplish your goal. For example, type this comment in the C# file:

C#
using System.Xml.Linq;

var doc = XDocument.Load("index.xhml");

// find all images

GitHub Copilot will suggest an implementation of the function. 要接受建议,请按 Tab

提示

If you receive limited or no suggestions from Copilot, you may have duplication detection enabled. For more information about duplication detection, see Managing Copilot policies as an individual subscriber.

Showing alternative suggestions

对于任何给定的输入,GitHub Copilot 可以提供多个建议。 可以选择要使用的建议,或拒绝所有建议。

For example, type this function signature in a C# file:

C#
int CalculateDaysBetweenDates(

GitHub Copilot will show you a suggestion.

Now hover over the suggestion to show the GitHub Copilot control for choosing suggestions. To display next or previous suggestions, click the forward or back arrow button in the control.

Alternatively, you can show alternate suggestions by pressing Alt+. (or Alt+,) on your keyboard.

要接受建议,请单击 Copilot 命令面板中的“接受”,或按 Tab。要拒绝所有建议,请按 Esc

Getting comment suggestions

注意

  • Comment suggestions are currently in 公共预览版 and are subject to change.
  • Comment suggestions are available in Visual Studio 17.14 Preview 2 and later.

GitHub Copilot can suggest comments for your code, by analyzing the code you write and generating comments that describe what the code does. For Copilot 免费版 users, comment suggestions count towards your monthly Copilot Chat usage, not your code suggestions usage.

Comment suggestions are available in the following languages:

  • C#
  • C++

Enabling comment suggestions

To enable comment suggestions, you need to configure the comment style in Visual Studio.

For C++

  1. In Visual Studio, in the Tools menu, click Options.
  2. In the left-side panel, click Text Editor.
  3. Click C++, then Code Style, then General.
  4. Under "Comments", select Xml Doc Comments from the dropdown.
  5. Select Insert existing comment style at the start of new lines when writing comments and Continue single line comments.

For C#

  1. In Visual Studio, in the Tools menu, click Options.
  2. In the left-side panel, click Text Editor.
  3. Click C#, then Advanced.
  4. Under "Comments", select Generate XML documentation comments for ///, Insert // at the start of new lines when writing // comments, and Insert * at the start of new lines when writing /* */ comments.

Using comment suggestions

To initiate comment suggestions, type the standard comment initiator for the language you are writing in (for example, ///), before the code you want to comment, and wait for the suggestion to appear.

To accept the suggestion, press Tab. To modify the suggestion, press Alt+/. To reject the suggestion, press Esc.

About 下一个编辑建议

Inline suggestions autocomplete code, but many development tasks involve editing existing code. 下一个编辑建议 assists with edits both at the cursor and in other relevant parts of the code, helping maintain consistency and streamline changes.

下一个编辑建议 predicts where and what edits may be needed based on ongoing changes. Suggestions may span a single symbol, an entire line, or multiple lines, depending on the scope of the potential change.

To enable 下一个编辑建议, see Configuring GitHub Copilot in your environment.

You can navigate suggested code changes using Tab, making it easier to find the next relevant edit without manually searching through files or references. Press Tab again to accept a suggestion.

An arrow in the gutter indicates an available edit suggestion. Click the arrow to access the edit suggestion menu, which provides keyboard shortcuts. If an edit suggestion is outside the current editor view, the arrow will point up or down to indicate where the next suggestion is.

About GitHub Copilot and Visual Studio Code

This guide demonstrates how to get coding suggestions from GitHub Copilot in Visual Studio Code. To see instructions for other popular coding environments, use the tool switcher at the top of the page.

Copilot in VS Code provides two kinds of suggestions:

  • Code completion. Copilot offers coding suggestions as you type. You can also describe something you want to do using natural language within a comment, and Copilot will suggest the code to accomplish your goal.
  • 下一个编辑建议 (公共预览版). Based on the edits you are making, Copilot will predict the location of the next edit you are likely to make and suggest a completion for it.

The examples in this guide use JavaScript, however other languages will work similarly. GitHub Copilot 为多种语言和各种框架提供建议,但尤其适用于 Python、JavaScript、TypeScript、Ruby、Go、C# 和 C++。 GitHub Copilot 还可以帮助生成数据库的查询,生成 API 和框架的建议,并可以帮助开发基础结构即代码。

Prerequisites

  • Access to Copilot. To use GitHub Copilot in Visual Studio Code, you need either limited access through Copilot 免费版 or a paid Copilot plan for full access. 有关如何访问 Copilot 的信息,请参阅“What is GitHub Copilot?”。

  • Sign in to GitHub in Visual Studio Code. See Set up GitHub Copilot in Visual Studio Code in the VS Code documentation..

  • Visual Studio Code. To use GitHub Copilot in Visual Studio Code, you must have Visual Studio Code installed. For more information, see the Visual Studio Code download page.

  • Copilot in Visual Studio Code. When you set up GitHub Copilot in Visual Studio Code for the first time, the required extensions are installed automatically. You don't need to download or install them manually. For detailed instructions, see Set up GitHub Copilot in Visual Studio Code in the Visual Studio Code documentation.

Getting code suggestions

GitHub Copilot offers coding suggestions as you type. For example, type this function header in a JavaScript file:

JavaScript
function calculateDaysBetweenDates(begin, end) {

GitHub Copilot will automatically suggest the rest of the function. 要接受建议,请按 Tab

You can also describe something you want to do using natural language within a comment, and Copilot will suggest the code to accomplish your goal. For example, type this comment in a JavaScript file:

JavaScript
// write a function to
// find all images without alternate text
// and give them a red border

GitHub Copilot will automatically suggest code. 要接受建议,请按 Tab

提示

If you receive limited or no suggestions from Copilot, you may have duplication detection enabled. For more information about duplication detection, see Managing Copilot policies as an individual subscriber.

Showing alternative suggestions

对于任何给定的输入,GitHub Copilot 可以提供多个建议。 可以选择要使用的建议,或拒绝所有建议。

For example, type this function header in a JavaScript file, and press Enter:

JavaScript
function calculateDaysBetweenDates(begin, end) {

GitHub Copilot will show you a suggestion.

Now hover over the suggestion to show the GitHub Copilot control for choosing suggestions. To display next or previous suggestions, click the forward or back arrow button in the control.

You can also use keyboard shortcuts to show alternative suggestions:

OSSee next suggestionSee previous suggestion
macOSOption (⌥) or Alt+]Option (⌥) or Alt+[
Windows or LinuxAlt+]Alt+[

要接受建议,请单击 Copilot 命令面板中的“接受”,或按 Tab。要拒绝所有建议,请按 Esc

Showing multiple suggestions in a new tab

如果不想使用 GitHub Copilot 提供的任何初始建议,可以在新选项卡中显示多个建议。

For example, type this function header in a JavaScript file, and press Enter:

JavaScript
function calculateDaysBetweenDates(begin, end) {

GitHub Copilot will show you a suggestion. Now press Ctrl+Enter to open a new tab with multiple additional options.

To accept a suggestion, below the suggestion, click Accept suggestion NUMBER. To reject all suggestions, close the tab.

Accepting partial suggestions

If you don't want to accept an entire suggestion from GitHub Copilot, you can accept the next word or the next line of a suggestion.

For example, type this function header in a JavaScript file, and press Enter:

JavaScript
function calculateDaysBetweenDates(begin, end) {

GitHub Copilot will automatically suggest an entire function body in grayed text. The exact suggestion may vary.

Now hover over the suggestion to show the GitHub Copilot control for choosing suggestions. To accept only the next word of the suggestion, click Accept Word in the control.

Alternatively, you can use a keyboard shortcut to accept the next word of a suggestion:

OSAccept Next Word
macOSCommand+
Windows or LinuxControl+

If you want to accept the next line of a suggestion, you will need to set a custom keyboard shortcut for the command editor.action.inlineSuggest.acceptNextLine. For more information on setting custom keyboard shortcuts, see Configuring GitHub Copilot in your environment.

About 下一个编辑建议

Inline suggestions autocomplete code, but many development tasks involve editing existing code. 下一个编辑建议 assists with edits both at the cursor and in other relevant parts of the code, helping maintain consistency and streamline changes.

下一个编辑建议 predicts where and what edits may be needed based on ongoing changes. Suggestions may span a single symbol, an entire line, or multiple lines, depending on the scope of the potential change.

To enable 下一个编辑建议, see Configuring GitHub Copilot in your environment.

You can navigate suggested code changes using Tab, making it easier to find the next relevant edit without manually searching through files or references. Press Tab again to accept a suggestion.

An arrow in the gutter indicates an available edit suggestion. Hover over the arrow to access the edit suggestion menu, which provides keyboard shortcuts and settings options. If an edit suggestion is outside the current editor view, the arrow will point up or down to indicate where the next suggestion is.

Screenshot of the gutter menu in Visual Studio Code. The arrow is outlined in dark orange.

For more details and examples, see Code completions with GitHub Copilot in VS Code in the Visual Studio Code documentation.

Changing the AI model

You can change the large language model that's used to generate code completion suggestions. For more information, see Changing the AI model for Copilot code completion.

About GitHub Copilot and Vim/Neovim

This guide demonstrates how to get coding suggestions from GitHub Copilot in Vim/Neovim. To see instructions for other popular coding environments, use the tool switcher at the top of the page.

Prerequisites

  • Access to Copilot. To use GitHub Copilot in Vim/Neovim, you need either limited access through Copilot 免费版 or a paid Copilot plan for full access. 有关如何访问 Copilot 的信息,请参阅“What is GitHub Copilot?”。

  • Compatible version of Vim/Neovim. To use GitHub Copilot in Vim/Neovim you must have Vim version 9.0.0185 / Neovim version 0.6 or above and Node.js version 18 or above installed. For more information, see the Vim / Neovim documentation and the Node.js website.

  • GitHub Copilot extension for Vim/Neovim. To use GitHub Copilot in Vim/Neovim, you must install the GitHub Copilot plugin. For more information, see Installing the GitHub Copilot extension in your environment.

Learning to use GitHub Copilot in Vim/Neovim

GitHub Copilot provides suggestions inline as you type in Vim/Neovim. To accept a suggestion, press the tab key.

For more information and guidance on using GitHub Copilot in Vim/Neovim run the following command to view the plugin documentation:

Shell
:help copilot

About GitHub Copilot and Azure Data Studio

This guide demonstrates how to get coding suggestions from GitHub Copilot in Azure Data Studio. To see instructions for other popular coding environments, use the tool switcher at the top of the page.

Prerequisites

  • Access to Copilot. To use GitHub Copilot in Azure Data Studio, you need either limited access through Copilot 免费版 or a paid Copilot plan for full access. 有关如何访问 Copilot 的信息,请参阅“What is GitHub Copilot?”。

  • Compatible version of Azure Data Studio. To use GitHub Copilot in Azure Data Studio, you must have Azure Data Studio version 1.44.0 or later installed. For more information, see the Azure Data Studio download page in the Azure Data Studio documentation.

  • GitHub Copilot extension for Azure Data Studio. To use GitHub Copilot in Azure Data Studio, you must install the GitHub Copilot extension. For more information, see Installing the GitHub Copilot extension in your environment.

Getting code suggestions

GitHub Copilot can provide you with inline suggestions as you create SQL databases in Azure Data Studio. For example, if you're writing a query that joins two tables, Copilot may suggest the join condition from columns in the open editor, other files in the workspace, and common syntax patterns.

In a SQL file, type the following query:

SQL
SELECT [UserId], [Red], [Orange], [Yellow], [Green], [Blue], [Purple], [Rainbow]
FROM [Tag].[Scoreboard]
INNER JOIN

GitHub Copilot will automatically suggest a join condition in grayed text. The exact suggestion may vary. 要接受建议,请按 Tab

You can also describe something you want to do using natural language within a comment, and Copilot will suggest the code to accomplish your goal. For example, type this comment in a SQL file:

SQL
SELECT TokenColor, COUNT(UserID) AS UserCount
FROM Tag.Users
GROUP BY TokenColor
-- pivot that query on tokencolor for Purple, Blue, Green, Yellow, Orange, Red
-- and rename the columns to match the colors
SELECT [Purple], [Blue], [Green], [Yellow], [Orange], [Red]

GitHub Copilot will automatically suggest code. 要接受建议,请按 Tab

提示

If you receive limited or no suggestions from Copilot, you may have duplication detection enabled. For more information on duplication detection, see Managing Copilot policies as an individual subscriber.

Showing alternative suggestions

For some suggestions, GitHub Copilot may provide multiple alternatives. You can select which suggestion you want to use, or reject all suggestions.

For example, type this query in a SQL file:

SQL
SELECT [UserId], [Red], [Orange], [Yellow], [Green], [Blue], [Purple], [Rainbow]
FROM [Tag].[Scoreboard]
INNER JOIN

GitHub Copilot will show you a suggestion.

Now hover over the suggestion to show the GitHub Copilot control for choosing suggestions. To display next or previous suggestions, click the forward or back arrow button in the control.

You can also use keyboard shortcuts to show alternative suggestions:

OSSee next suggestionSee previous suggestion
macOSOption+[Option+]
Windows or LinuxAlt+[Alt+]

To accept a suggestion, click "Accept" in the Copilot control, or press Tab. To reject all suggestions, press Esc.

Accepting partial suggestions

If you don't want to accept an entire suggestion from GitHub Copilot, you can accept the next word or the next line of a suggestion.

For example, type this query in a SQL file:

SQL
SELECT [UserId], [Red], [Orange], [Yellow], [Green], [Blue], [Purple], [Rainbow]
FROM [Tag].[Scoreboard]
INNER JOIN

GitHub Copilot will show you a suggestion in grayed text. The exact suggestion may vary.

Now hover over the suggestion to show the GitHub Copilot control for choosing suggestions. To accept only the next word of the suggestion, click Accept Word in the control.

Alternatively, you can use a keyboard shortcut to accept the next word of a suggestion:

OSAccept Next Word
macOSCommand+
Windows or LinuxControl+

If you want to accept the next line of the suggestion, you will need to set a custom keyboard shortcut for the command editor.action.inlineSuggest.acceptNextLine. For more information on setting custom keyboard shortcuts, see Keyboard shortcuts in Azure Data Studio in the Microsoft documentation.

About GitHub Copilot in Xcode

This guide demonstrates how to get coding suggestions from GitHub Copilot in Xcode. To see instructions for other popular coding environments, use the tool switcher at the top of the page.

Prerequisites

  • Access to Copilot. To use GitHub Copilot in Xcode, you need either limited access through Copilot 免费版 or a paid Copilot plan for full access. 有关如何访问 Copilot 的信息,请参阅“What is GitHub Copilot?”。

  • GitHub Copilot extension for Xcode. To use GitHub Copilot for Xcode, you must install the GitHub Copilot for Xcode extension. See Installing the GitHub Copilot extension in your environment.

Getting code suggestions

GitHub Copilot offers coding suggestions as you type. For example, type this function signature in a Swift file:

Swift
func calculateDaysBetweenDates(

GitHub Copilot will automatically suggest an entire function body in grayed text. To accept the first line of a suggestion, press Tab. To view the full suggestion, hold Option, and to accept the full suggestion, press Option+Tab.

Improving code suggestions

If you encounter issues with code suggestions, such as conflicting or missing suggestions, you can try the following:

  • Disable Xcode's native predictive text completion: To avoid receiving two sets of code suggestions, you can disable Xcode's native predictive text completion. You can find this setting in the Xcode settings in the "Editing" tab under "Text Editing".
  • Check for duplication detection in Copilot: If you receive limited or no suggestions from Copilot, you may have duplication detection enabled. For more information on duplication detection, see Managing Copilot policies as an individual subscriber.
  • Check for updates and restart Xcode: Ensure you have the latest version of Copilot for Xcode in the extension application and restart Xcode.

You can also open an issue in the Copilot for Xcode repository.

About GitHub Copilot and Eclipse

This guide demonstrates how to get coding suggestions from GitHub Copilot in Eclipse. To see instructions for other popular coding environments, use the tool switcher at the top of the page.

Prerequisites

  • Access to Copilot. To use GitHub Copilot in Eclipse, you need either limited access through Copilot 免费版 or a paid Copilot plan for full access. 有关如何访问 Copilot 的信息,请参阅“What is GitHub Copilot?”。

  • GitHub Copilot extension for Eclipse.To use GitHub Copilot in Eclipse, you must install the GitHub Copilot extension. See Installing the GitHub Copilot extension in your environment.

Getting code suggestions

GitHub Copilot offers coding suggestions as you type. For example, type this function header in a Java file:

Java
public int getDiff(int a, int b)

GitHub Copilot will automatically suggest the rest of the function. 要接受建议,请按 Tab。 To discard the suggestion, press Esc.

You can also describe something you want to do using natural language within a comment, and Copilot will suggest the code to accomplish your goal. For example, type this comment in a Java file:

Java
/*
 * Return the difference between two different integers.
 */

GitHub Copilot will automatically suggest code.

提示

If you receive limited or no suggestions from Copilot, you may have duplication detection enabled. For more information about duplication detection, see Managing Copilot policies as an individual subscriber.

Manually triggering code completion

You can also use keyboard shortcuts to trigger code completion.

OSTrigger code completion
macOSOption+Command+/
Windows or LinuxCtrl+Alt+/

Accepting partial suggestions

If you don't want to accept an entire suggestion from Copilot, you can accept the next word of a suggestion.

OSAccept next word
macOSCommand+
Windows or LinuxCtrl+

Next steps