Skip to main content

Comprehensive Guide to GitHub Copilot Commands

Comprehensive Guide to GitHub Copilot Commands
Deepak Kamboj
Senior Software Engineer
5 min read
Git

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

TaskCommand / ShortcutDescription
Enable GitHub Copilot in VS CodeCommand Palette: GitHub Copilot: EnableActivates GitHub Copilot in your VS Code editor.
Disable GitHub Copilot in VS CodeCommand Palette: GitHub Copilot: DisableDeactivates GitHub Copilot in your VS Code editor.
Accept Copilot suggestionTabInserts the selected Copilot suggestion into your code.
Dismiss Copilot suggestionEscDismisses the current suggestion.
View additional suggestionsAlt + ] / Alt + [Cycles through multiple suggestions.
Trigger a suggestion manuallyCtrl + 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.

TaskCommand / CommentDescription
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.

TaskCommand / ShortcutDescription
Auto-complete a line of codeStart typingCopilot suggests a completion for the current line of code.
Complete multiple lines of codeStart typing or add a trigger wordCopilot suggests completions for multiple lines of code at once.
Continue an unfinished functionBegin the function bodyCopilot 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.

TaskCommand / ShortcutDescription
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 functionSuggests 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.

TaskCommand / CommentDescription
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.

TaskCommand / CommentDescription
Provide suggestions without auto-insertCommand Palette: GitHub Copilot: Toggle Suggestions InlinePrevents Copilot from auto-inserting code, allowing manual insertion only when approved.
Collaborate on suggestionsCommand Palette: GitHub Copilot: Show Side-by-Side SuggestionsDisplays 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.

LanguageCommand / CommentDescription
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.

TaskCommand / ShortcutDescription
Open Copilot settingsCommand Palette: GitHub Copilot: SettingsOpens the settings panel for configuring GitHub Copilot.
Enable/Disable inline suggestionsCommand Palette: GitHub Copilot: Toggle Inline SuggestionsControls whether Copilot provides inline code suggestions or not.
Adjust Copilot's behaviorCommand Palette: GitHub Copilot: ConfigureAccesses advanced configuration options for GitHub Copilot.
Set up keybindingsKeyboard Shortcuts PanelAssign custom keybindings for Copilot commands in your editor.

Miscellaneous

Other useful commands and features that enhance your coding experience with GitHub Copilot.

TaskCommand / ShortcutDescription
View GitHub Copilot documentationCommand Palette: GitHub Copilot: Open DocsOpens the official GitHub Copilot documentation.
Give feedback on a suggestionAlt + \Opens a feedback form for the current suggestion, allowing you to rate its usefulness.
Enable Copilot LabsCommand Palette: GitHub Copilot Labs: EnableActivates experimental features and commands in GitHub Copilot Labs.
View Copilot's suggestions logCommand Palette: GitHub Copilot: View LogDisplays 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.