Copilot Essentials
Master GitHub Copilot's code completion engine — from initial setup and your first suggestion to advanced techniques for tests, documentation, and refactoring.
What Is GitHub Copilot and How It Works
GitHub Copilot is an AI pair programmer that suggests code as you type. It works by sending context from your open file — the code above your cursor, the filename, imported modules, and comments — to a large language model running in the cloud. The model returns one or more suggested completions, which appear as grey "ghost text" in your editor.
Copilot is not a search engine that copies code from the internet. It is a generative model that synthesizes new code based on patterns learned during training. This means it can produce code you have never seen before, tailored to your specific context.
Key facts about how Copilot works:
- Copilot reads the current file, open tabs, and neighboring files to build context
- Suggestions are generated in real time, typically in under 500 milliseconds
- It supports virtually every programming language, but works best with Python, JavaScript/TypeScript, Go, Ruby, Java, C#, and C++
- A built-in filter blocks suggestions that match public code verbatim (optional, enabled by default on Business/Enterprise)
Setting Up Copilot
Getting started with Copilot takes less than five minutes. Here are the plans available:
| Plan | Price | Completions | Chat Messages | Best For |
|---|---|---|---|---|
| Copilot Free | $0 | 2,000/month | 50/month | Students, hobbyists, trying it out |
| Copilot Pro | $10/month | Unlimited | Unlimited | Individual professional developers |
| Copilot Business | $19/user/month | Unlimited | Unlimited | Teams needing admin controls and policies |
| Copilot Enterprise | $39/user/month | Unlimited | Unlimited | Organizations needing fine-tuning and IP indemnity |
To set up Copilot in VS Code:
- Go to github.com/settings/copilot and enable Copilot on your account
- Open VS Code and install the GitHub Copilot extension from the marketplace
- Sign in with your GitHub account when prompted
- Open any code file and start typing — suggestions will appear automatically
Code Completion: The Core Experience
Copilot's code completion is context-aware and proactive. Here is how to work with it effectively:
Accepting suggestions:
- Tab — Accept the entire suggestion
- Ctrl+Right Arrow (Windows/Linux) or Cmd+Right Arrow (Mac) — Accept word by word
- Esc — Dismiss the current suggestion
- Alt+] / Alt+[ — Cycle through alternative suggestions
Here is an example of Copilot completing a function from a descriptive name and comment:
# Calculate the compound interest given principal, rate, time, and compounding frequency
def calculate_compound_interest(principal, annual_rate, years, n_compounding=12):
# Copilot suggests the entire function body:
amount = principal * (1 + annual_rate / n_compounding) ** (n_compounding * years)
interest = amount - principal
return round(interest, 2)And a multi-line completion for a React component:
// A reusable button component with loading state
function LoadingButton({ label, isLoading, onClick, disabled }) {
// Copilot suggests:
return (
<button
onClick={onClick}
disabled={disabled || isLoading}
className={`btn ${isLoading ? 'btn-loading' : ''}`}
>
{isLoading ? (
<span className="spinner" aria-hidden="true" />
) : null}
{isLoading ? 'Loading...' : label}
</button>
);
}Copilot in Different Editors
Copilot behaves consistently across editors, but each environment has its own integration style:
| Editor | Extension Name | Unique Feature |
|---|---|---|
| VS Code | GitHub Copilot | Deepest integration: inline chat, chat panel, Copilot Edits multi-file editing |
| JetBrains IDEs | GitHub Copilot | Works across all JetBrains products (IntelliJ, PyCharm, WebStorm, Rider, etc.) |
| Neovim | copilot.vim | Lightweight, keyboard-driven experience for terminal enthusiasts |
| Visual Studio | GitHub Copilot | Integrated with IntelliSense and .NET-specific tooling |
| Xcode | Copilot for Xcode | Swift and Objective-C completion with Xcode-native UI |
Regardless of your editor, the keyboard shortcuts for accepting and cycling suggestions follow the same pattern. The VS Code experience is the most feature-rich because GitHub and Microsoft invest heavily in it as the primary Copilot surface.
Using Copilot for Tests, Docs, and Refactoring
Code completion is just the beginning. Copilot excels at three other critical development tasks:
Writing Tests
Open a test file, import your function, and write a descriptive test name. Copilot will generate the test body:
import pytest
from finance import calculate_compound_interest
def test_compound_interest_monthly():
# $1000 at 5% for 10 years, compounded monthly
result = calculate_compound_interest(1000, 0.05, 10, 12)
assert result == 647.01 # expected compound interest
def test_compound_interest_zero_rate():
result = calculate_compound_interest(1000, 0.0, 5, 12)
assert result == 0.0
def test_compound_interest_single_year():
result = calculate_compound_interest(5000, 0.08, 1, 4)
assert result == 412.16 # quarterly compounding for 1 yearGenerating Documentation
Place your cursor inside a function and type a docstring opener. Copilot fills in parameter descriptions, return values, and examples:
def calculate_compound_interest(principal, annual_rate, years, n_compounding=12):
"""
Calculate compound interest on a principal amount.
Args:
principal (float): The initial investment amount.
annual_rate (float): The annual interest rate as a decimal (e.g., 0.05 for 5%).
years (int): The number of years to compound.
n_compounding (int): Number of times interest is compounded per year. Default is 12 (monthly).
Returns:
float: The total interest earned, rounded to 2 decimal places.
Example:
>>> calculate_compound_interest(1000, 0.05, 10)
647.01
"""Refactoring Code
Write a comment describing the refactoring you want, and Copilot will generate the improved version. For example:
// Refactor: convert this callback-based function to use async/await
async function fetchUserData(userId) {
try {
const response = await fetch(`/api/users/${userId}`);
if (!response.ok) throw new Error(`HTTP ${response.status}`);
const data = await response.json();
return data;
} catch (error) {
console.error('Failed to fetch user data:', error);
throw error;
}
}How Copilot Models Work
Under the hood, Copilot is powered by large language models. As of 2025, you can choose between multiple models:
- GPT-4o — The default model for most Copilot features. Fast, accurate, and great for code completion.
- Claude 3.5 Sonnet (Anthropic) — Available as an alternative in Copilot Chat. Known for careful, detailed reasoning and long-context understanding.
- Gemini (Google) — Available in select Copilot features, offering strong multi-language capabilities.
- Custom/fine-tuned models — Enterprise customers can fine-tune models on their own codebase for improved suggestions.
You can switch models in Copilot Chat by clicking the model selector dropdown in the chat panel. For code completion, the model is selected automatically by GitHub to optimize for speed and quality.
Lilly Tech Systems