If you’ve ever wished your code editor could read your mind, GitHub Copilot comes close.
Powered by OpenAI’s Codex model, GitHub Copilot acts like an AI pair programmer that suggests code snippets, functions, and even entire files right inside your editor. Whether you’re writing Python scripts, Java classes, or full-stack apps, Copilot saves you time by auto-completing what you’re about to type.
In this guide, you’ll learn how to use GitHub Copilot to generate code on your Windows 11 machine — from installation to writing your first AI-assisted function.
What You’ll Need Before You Start
Make sure you have the following:
- A GitHub account (free or paid; Copilot offers a 30-day trial)
- Visual Studio Code (VS Code) installed
- Internet connection (Copilot runs via GitHub’s cloud service)
Optional but recommended: a GitHub Copilot subscription for continuous access after the trial.
Step 1: Install Visual Studio Code
If you don’t have VS Code yet:
- Go to https://code.visualstudio.com/.
- Click Download for Windows and run the installer.
- During setup, check “Add to PATH” and “Register code as editor for supported file types.”
- Finish the installation and launch VS Code.
Step 2: Install the GitHub Copilot Extension
- Open VS Code.
- Click the Extensions icon on the left sidebar or press
Ctrl + Shift + X. - In the search bar, type:
GitHub Copilot - Select the official extension from GitHub.
- Click Install.
When the installation completes, you’ll see the Copilot icon appear in the status bar.
Tip: There’s also GitHub Copilot Chat for conversational help, but you only need the core extension for inline code generation.
Step 3: Sign In to GitHub Copilot
- After installation, a pop-up will ask you to sign in to GitHub.
- Click Sign In → your browser will open.
- Log into your GitHub account and authorize Visual Studio Code to use Copilot.
- Return to VS Code — you’ll see a confirmation message like:
GitHub Copilot is now active.
Now Copilot is ready to start generating code!
Step 4: Create a New Project or File
Let’s try Copilot in action.
- Go to File → New File.
- Save it with an extension for your preferred language — for example,
hello.pyorindex.js - Start typing a comment that describes what you want.
Example:
# Write a Python function that checks if a number is prime
Within seconds, Copilot will suggest the entire function automatically — you’ll see it appear in faded gray text below your cursor.
Step 5: Accept or Edit Copilot Suggestions
To accept the suggestion, press:
- Tab → accept the whole suggestion.
- Ctrl + ] / Ctrl + [ → cycle through multiple suggestions.
- Esc → dismiss the current suggestion.
Copilot learns from your edits and future prompts — so the more you use it, the better it gets at matching your coding style.
Step 6: Generate Entire Code Blocks or Functions
Copilot doesn’t just finish lines — it can generate entire algorithms or APIs.
Example 1: Generate a Calculator Function
Type:
// Create a simple calculator class with add, subtract, multiply, and divide methods
Copilot might produce:
class Calculator {
add(a, b) { return a + b; }
subtract(a, b) { return a - b; }
multiply(a, b) { return a * b; }
divide(a, b) { return b !== 0 ? a / b : null; }
}
Example 2: Generate a REST API Endpoint
Type:
# Create a Flask API endpoint to return a list of users
Copilot will instantly generate a working Flask route.
Step 7: Use Copilot Chat for Natural-Language Prompts (Optional)
If you also install GitHub Copilot Chat, you can talk to the AI directly inside VS Code.
- Open the Chat panel (
Ctrl + Ior click the Copilot icon). - Ask questions like:
Generate a React component for a login form. - Copilot Chat will output the full code snippet with explanations.
You can insert it into your file with one click.
Step 8: Improve Suggestions with Context
Copilot works best when it understands your codebase. To give it context:
- Include meaningful comments and docstrings.
- Keep related files open — Copilot reads from visible editors.
- Use consistent variable names.
Example:
# Fetch data from an API, parse JSON, and print results
Copilot will automatically generate code that fetches and parses JSON using request
Step 9: Control Copilot Behavior
You can tweak Copilot’s behavior in VS Code:
- Go to File → Preferences → Settings.
- Search for “Copilot”.
- Adjust options like:
- Enable/Disable Copilot per language
- Inline suggestions
- Telemetry and privacy
You can also toggle Copilot on/off quickly by pressing Ctrl + Alt +\.
Wrapping Up
And that’s it! You’ve successfully learned how to use GitHub Copilot to generate code inside Visual Studio Code on Windows 11.
With just a few keystrokes, Copilot can help you write functions, APIs, or even full-stack templates — freeing you to focus on logic and creativity instead of boilerplate.
Whether you’re a beginner learning to code or an experienced developer streamlining workflows, Copilot can be your always-on AI coding partner.