Below is a handy cheat sheet for using GitHub Copilot in Visual Studio Code. It covers setup, common commands, best practices, and helpful tips to get the most out of Copilot’s AI-assisted coding features. Feel free to adjust it to your own workflow!
- GitHub Copilot in VS Code cheat sheet
-
https://code.visualstudio.com/docs/copilot/copilot-vscode-features
- Copilot Chat Cookbook
-
https://docs.github.com/en/copilot/example-prompts-for-github-copilot-chat
1. Setup
-
Configure Settings (optional)
-
Go to File > Preferences > Settings (Windows/Linux) or Code > Preferences > Settings (macOS).
-
Search for “Copilot” to see configuration options (e.g., inline suggestions, enabling/disabling suggestions).
-
2. Basic Usage
-
Inline Suggestions
-
Start typing your code; Copilot will suggest completions inline (semi-transparent text).
-
Press Tab to accept the suggestion or keep typing to let Copilot refine it.
-
-
Multi-line Suggestions
-
Type a descriptive comment or function signature.
-
Copilot often generates multi-line code blocks following that comment.
-
Accept with Tab or Enter (depending on your settings).
-
-
Ask Copilot in Comments
-
You can write a comment describing what you want, e.g.,
// Create a function that sums an array of numbers
, and Copilot will try to generate the solution below.
-
-
Trigger Suggestions Manually
-
Sometimes you need to re-trigger suggestions (especially if they didn’t appear automatically).
-
Use Ctrl + Space (Windows/Linux) or Cmd + Space (macOS) to open IntelliSense suggestions (which can include Copilot suggestions).
-
3. Keyboard Shortcuts & Commands
Some shortcuts may differ depending on your OS or personal keybindings. Below are the most commonly used ones out of the box. |
Action | Windows/Linux | macOS |
---|---|---|
Accept Copilot suggestion (inline) |
|
|
Show next Copilot suggestion |
|
|
Show previous Copilot suggestion |
|
|
Manually trigger suggestions (IntelliSense) |
|
|
Open Commands Palette |
|
|
Quick Commands via Command Palette
-
GitHub Copilot: Enable (turn on suggestions)
-
GitHub Copilot: Disable (turn off suggestions)
-
GitHub Copilot: Open Chat (for Chat Beta users)
Just open the Command Palette and type “Copilot” to see these commands.
4. Working with Suggestions
-
Reviewing Multiple Suggestions
-
If you see a suggestion inline but want to check more options, use
Alt + ]
(Windows) /Option + ]
(macOS) to cycle to the next suggestion. -
Likewise,
Alt + [
(Windows) /Option + [
(macOS) goes to the previous suggestion.
-
-
Partial Acceptance
-
If only part of the suggestion is useful, you can accept it and then edit the rest.
-
-
Context Matters
-
Copilot’s suggestions are heavily influenced by the surrounding code and comments. Provide meaningful function names, comments, and docstrings for better suggestions.
-
5. Tips & Best Practices
-
Use Comments for Clarity
-
The more descriptive your comment, the better Copilot can guess your intentions.
-
Example:
// Generate a React component that displays a user’s profile information
-
-
Check Security & Accuracy
-
Copilot is not always perfect. Always review generated code for correctness, security issues, or licensing concerns.
-
-
Experiment with Different Prompts
-
Try short prompts for quick suggestions and longer, detailed prompts for more complex tasks.
-
-
Leverage Snippets
-
Combine Copilot with your existing code snippets for a hybrid approach.
-
-
Disable/Enable for Sensitive Code
-
If you’re working on sensitive or proprietary code, you can temporarily disable Copilot to ensure no code suggestions are generated.
-
6. Common Use Cases
-
Rapid Prototyping
-
Outline functions or data structures quickly.
-
-
Boilerplate Code
-
Generate repetitive code (e.g., error-handling, common patterns).
-
-
Refactoring Assistance
-
Provide a comment for how you want to refactor; Copilot may suggest partial or complete refactors.
-
-
Learning New APIs
-
Use Copilot suggestions to see example usage of libraries/APIs you’re unfamiliar with.
-
7. Troubleshooting
-
Suggestions Not Appearing
-
Make sure you’re logged in to GitHub, and Copilot is enabled.
-
Check your User Settings → Copilot is turned On.
-
Ensure your environment (language server, network, etc.) is working correctly.
-
-
Conflicts with IntelliSense
-
Sometimes VS Code’s IntelliSense might overshadow Copilot suggestions. You can change the Copilot suggestion display setting in the extension settings (e.g., inline vs. separate panel).
-
-
Rate Limits
-
GitHub Copilot has certain rate limits. If you exceed them, suggestions might be delayed or missing temporarily.
-
8. Resources
-
GitHub Copilot Docs: docs.github.com/copilot
-
Visual Studio Code Marketplace (GitHub Copilot extension page)
-
GitHub Copilot Community (Discussion boards, Q&A, troubleshooting)
Final Thoughts
GitHub Copilot in VS Code can supercharge your workflow by accelerating code generation and reducing boilerplate. However, always review and test the AI-generated code to ensure it meets your project’s requirements and standards.
Happy coding with Copilot!