GitHub Copilot is an AI-powered coding assistant that helps developers by providing code suggestions and automating repetitive coding tasks. This document outlines the key commands, features, and usage scenarios for GitHub Copilot.
Activation and Basic Commands
Task | Command / Shortcut | Description |
---|---|---|
Enable GitHub Copilot in VS Code | Command Palette: GitHub Copilot: Enable | Activates GitHub Copilot in your VS Code editor. |
Disable GitHub Copilot in VS Code | Command Palette: GitHub Copilot: Disable | Deactivates GitHub Copilot in your VS Code editor. |
Accept Copilot suggestion | Tab | Inserts the selected Copilot suggestion into your code. |
Dismiss Copilot suggestion | Esc | Dismisses the current suggestion. |
View additional suggestions | Alt + ] / Alt + [ | Cycles through multiple suggestions. |
Trigger a suggestion manually | Ctrl + Enter (Windows/Linux) or Cmd + Enter (Mac) | Manually triggers Copilot to generate code suggestions. |
Comment-Based Commands
GitHub Copilot can be directed using comments to produce specific code snippets, examples, or logic.
Task | Command / Comment | Description |
---|---|---|
Generate a function | // Function to <description> | Provides a function based on the description in the comment. |
Complete a class definition | // Class for <description> | Suggests a full class definition with methods and properties based on the comment. |
Explain a piece of code | // Explain this code: | Produces a comment that explains the following code snippet. |
Write a test function | // Test for <function_name> | Generates a test function for the specified function. |
Create a documentation comment | /** | Starts a block comment, and Copilot will auto-suggest a detailed documentation comment. |
Code Completion Commands
GitHub Copilot can automatically complete your code based on the context provided by your current file.
Task | Command / Shortcut | Description |
---|---|---|
Auto-complete a line of code | Start typing | Copilot suggests a completion for the current line of code. |
Complete multiple lines of code | Start typing or add a trigger word | Copilot suggests completions for multiple lines of code at once. |
Continue an unfinished function | Begin the function body | Copilot suggests how to complete the function based on its name and initial comments. |
Advanced Suggestions
GitHub Copilot can be used for more advanced coding scenarios, including refactoring, generating boilerplate code, and handling specific languages or frameworks.
Task | Command / Shortcut | Description |
---|---|---|
Generate boilerplate code | // Boilerplate for <framework/task> | Creates boilerplate code for a specific framework or task, such as setting up a new API endpoint. |
Suggest refactoring | // Refactor this function | Suggests a refactor for the code based on common best practices. |
Optimize code for performance | // Optimize this code for <goal> | Provides performance optimization suggestions based on the specified goal (e.g., speed, memory). |
Suggest code in specific language | // Write in <language> | Instructs Copilot to generate code in a specific programming language. |
Testing and Debugging
GitHub Copilot can assist with writing tests, debugging code, and providing potential fixes.
Task | Command / Comment | Description |
---|---|---|
Generate unit tests | // Write unit tests for <function/class> | Automatically writes unit tests for the specified function or class. |
Provide test cases | // Provide test cases for <scenario> | Suggests multiple test cases for a given scenario or function. |
Suggest bug fixes | // Fix this bug: | Suggests potential bug fixes or improvements based on the existing code. |
Debug a function | // Debug <function_name> | Offers debugging tips or inserts debugging code such as logging statements. |
Copilot in Pair Programming
When paired with another developer or using pair programming practices, GitHub Copilot can still assist without taking over the coding session.
Task | Command / Comment | Description |
---|---|---|
Provide suggestions without auto-insert | Command Palette: GitHub Copilot: Toggle Suggestions Inline | Prevents Copilot from auto-inserting code, allowing manual insertion only when approved. |
Collaborate on suggestions | Command Palette: GitHub Copilot: Show Side-by-Side Suggestions | Displays suggestions in a side panel for collaborative review and discussion. |
Review generated code | // Review this code: | Requests Copilot to generate comments or reviews for the current code snippet. |
Language-Specific Commands
GitHub Copilot is language-agnostic, but you can tailor its suggestions to specific languages by using commands or comments relevant to the language's syntax or idioms.
Language | Command / Comment | Description |
---|---|---|
Python | # Function to <task> | Generates Pythonic code with appropriate idioms and best practices. |
JavaScript/TypeScript | // Create a <task> | Suggests JavaScript or TypeScript code depending on the context and file type. |
SQL | -- Query to <task> | Generates SQL queries or scripts based on the provided description. |
HTML/CSS | <!-- HTML code to <task> --> | Produces HTML or CSS code snippets for web development tasks. |
Settings and Customization
Users can customize how GitHub Copilot behaves within their IDE or editor.
Task | Command / Shortcut | Description |
---|---|---|
Open Copilot settings | Command Palette: GitHub Copilot: Settings | Opens the settings panel for configuring GitHub Copilot. |
Enable/Disable inline suggestions | Command Palette: GitHub Copilot: Toggle Inline Suggestions | Controls whether Copilot provides inline code suggestions or not. |
Adjust Copilot's behavior | Command Palette: GitHub Copilot: Configure | Accesses advanced configuration options for GitHub Copilot. |
Set up keybindings | Keyboard Shortcuts Panel | Assign custom keybindings for Copilot commands in your editor. |
Miscellaneous
Other useful commands and features that enhance your coding experience with GitHub Copilot.
Task | Command / Shortcut | Description |
---|---|---|
View GitHub Copilot documentation | Command Palette: GitHub Copilot: Open Docs | Opens the official GitHub Copilot documentation. |
Give feedback on a suggestion | Alt + \ | Opens a feedback form for the current suggestion, allowing you to rate its usefulness. |
Enable Copilot Labs | Command Palette: GitHub Copilot Labs: Enable | Activates experimental features and commands in GitHub Copilot Labs. |
View Copilot's suggestions log | Command Palette: GitHub Copilot: View Log | Displays a log of all suggestions made during the current session. |
This guide should help you make the most of GitHub Copilot's capabilities, enhancing your productivity and coding experience.