Inline Completion

Inline Completion Mastery

Inline completion is the feature most people think of when they hear "GitHub Copilot." It is also the one most people underuse. This lesson covers every aspect of it so you can get maximum value with minimum friction.

How it triggers

Copilot watches what you type and sends the surrounding code to the model. Suggestions appear as soon as the model responds — usually within a second. The trigger is just you writing code. You do not press a special key to request a suggestion; it arrives automatically.

The suggestion is based on:

  • Everything in the current file, especially the code immediately around your cursor
  • Other open editor tabs (Copilot selects the most relevant ones automatically)
  • Your copilot-instructions.md file if present

Accepting, cycling, dismissing

Accept the full suggestion: Tab

Accept word by word: On macOS, Cmd + Right Arrow accepts the next word of the suggestion. On Windows/Linux, Ctrl + Right Arrow. Use this when the suggestion is mostly right but you want to make small edits as you go.

Cycle to the next suggestion: Alt + ] (both platforms). Copilot often has 2–5 alternative suggestions. If the first is not right, cycle through them. This is dramatically underused.

Cycle to the previous suggestion: Alt + [

Dismiss suggestion: Escape

See all suggestions in a panel: Ctrl + Enter (VS Code) opens a panel showing up to 10 alternatives. Useful for complex functions where you want to compare options.

When to write a comment first

The single most effective technique for better inline completions: write a comment before the code you want. Treat the comment as a specification.

typescript
// Debounce a function call. When the returned function is called, wait `delay` ms // before invoking `fn`. If called again before the delay expires, reset the timer. // Returns the debounced function. function debounce<T extends (...args: any[]) => void>(fn: T, delay: number) {

That comment tells the model: what the function does, the key behavior (reset on re-call), and the return type. The suggestion will be far more accurate than if you had just typed function debounce(fn, delay) {.

When to let the file speak

Sometimes you do not need a comment because the file already has enough signal. For example:

  • You have a User interface defined above. You start typing function createUser( — Copilot sees the interface and suggests a function that accepts the right fields.
  • You have three test cases following a pattern. You start writing a fourth — Copilot suggests the next test following the same pattern.
  • You have a switch statement with four cases. You add a fifth case "x": — Copilot suggests the body based on the other cases.

Learning to recognize when context is already sufficient versus when you need to add a comment is a skill that develops over a few weeks of use.

Patterns that trigger great completions

Function from signature + comment:

python
def calculate_compound_interest( principal: float, annual_rate: float, periods_per_year: int, years: int ) -> float: """ Calculate compound interest. Formula: principal * (1 + rate/periods)^(periods*years) """

Test from function name:

javascript
test("returns empty array when input is empty", () => {

Config from existing entries:

yaml
routes: - path: /users handler: userHandler methods: [GET, POST] - path: /products handler: productHandler # Copilot suggests methods based on pattern

SQL from schema:

sql
-- Schema: users(id, email, created_at), orders(id, user_id, total, created_at) -- Get the top 10 users by total order value in the last 30 days SELECT

When inline completion gets in the way

Inline completion is not always the right tool:

  • Complex algorithms. If you need to implement binary search on a custom data structure, write the outline yourself and use Chat to fill in the tricky parts.
  • Security-sensitive code. Crypto implementations, input sanitization, authentication flows — write these yourself or use Chat where you can review the explanation along with the code.
  • When it keeps suggesting the same wrong thing. Press Escape, write a few more characters to redirect it, or switch to Chat and describe what you want explicitly.
  • When you are in a learning mode. If you are trying to learn a new algorithm or pattern, write it yourself. Accepting AI completions without understanding them defeats the learning purpose.

The Tab habit and its dangers

After a few weeks with Copilot, pressing Tab becomes instinctive. This is efficient but dangerous if you stop reading what you accept. Periodically audit yourself: are you reading every suggestion before accepting it, or just pressing Tab reflexively? The latter leads to bugs, security issues, and code that does not fit your project.

The discipline to maintain: for any suggestion longer than three or four lines, read it before pressing Tab. For single-line completions of obvious things (closing a bracket, a standard return statement), reflexive Tab is fine.