Sub topic 11
Configure Copilot per language
This chapter assumes you can open VS Code settings, edit settings.json, and find a language identifier. It also assumes Copilot is installed and you are signed in. Here you will control where inline suggestions appear, so they help in code and stay out of prose.
Why configure per language
Inline suggestions are useful in source code. In plain text, Markdown, or commit messages they can be noise, or they can offer text you don't want in documents. Copilot lets you switch suggestions on or off for each language.
The setting that controls this is github.copilot.enable. It is an object. Each key is either a language identifier or *, which matches every language. Each value is true or false.
The github.copilot.enable setting
Open the Command Palette, run Preferences: Open User Settings (JSON), and add this:
{
"github.copilot.enable": {
"*": true,
"plaintext": false,
"markdown": false
}
}This does three things:
"*": truekeeps suggestions on for every language by default."plaintext": falseturns them off for plain text files."markdown": falseturns them off for Markdown files.
A specific language key overrides the * entry. You can also invert the pattern. Set "*": false and then list only the languages where you want Copilot, such as "python": true.
{
"github.copilot.enable": {
"*": false,
"python": true,
"typescript": true
}
}Find the language identifier
The key must be the language identifier, not the file extension. Markdown is markdown, not md. To find the identifier for the open file, click the language name in the status bar at the bottom right. VS Code shows a language picker, and the identifier appears next to each language name. A wrong key does not raise an error. The setting is silently ignored for the language you meant.
Toggle without editing JSON
You do not always need to edit settings. Click the Copilot icon in the status bar to open its menu. From there you can turn suggestions off for the current language or globally. This updates the same github.copilot.enable setting, so it is a quick way to see what VS Code writes for you.
User and workspace scope
Settings can live in two places:
| Scope | File | Effect |
|---|---|---|
| User | Your user `settings.json` | Applies in every window on your machine. |
| Workspace | `.vscode/settings.json` in a project | Applies only to that project, and overrides user settings. |
Use workspace settings when a project has specific needs, for example a documentation repository where you want markdown off. Commit the file if the whole team should share it. Keep personal preferences in your user settings.
Verify the change
- Save
settings.json. - Open a file in a language you disabled, such as a
.mdfile, and type a sentence. No grey suggestion text should appear. - Open a file in an enabled language and type a descriptive comment followed by a function signature:
# Return the n-th Fibonacci number using iteration
def fibonacci(n):A grey suggestion should appear. Press Tab to accept it.
Common mistakes
- Using the extension as the key.
"md": falsedoes nothing. Usemarkdown. - Invalid JSON. A trailing comma or a missing quote can make VS Code ignore the block. Watch for the red squiggles in the editor.
- Forgetting workspace overrides. If the user setting says
truebut suggestions are missing, check.vscode/settings.jsonin the open project. - Expecting changes in other features. This setting only affects inline suggestions.
Exercise
Exercise
You want Copilot suggestions on everywhere except in Markdown and plain text files, but only for one project, not on your whole machine. Which file do you edit, and what do you put in it?
Show answer
Edit .vscode/settings.json in that project, the workspace settings file. Add "github.copilot.enable": { "*": true, "plaintext": false, "markdown": false }. The workspace scope applies only to that project and overrides your user settings.
Exercise
You add "md": false to github.copilot.enable, but suggestions still appear in README.md. Why, and how do you fix it?
Show answer
The key must be the language identifier, which is markdown, not the extension md. VS Code does not report an error for the unknown key. Change the key to markdown.