How to specify the text font for specific file types?

Viewed 469

I know how to set the font family for the editor globally in VS Code.

But I don't know how to change the font for a specific type of file, e.g., *.txt with sans serif font.

Is there any way I can change the font for a specific type of file in VS Code?

1 Answers

VS Code supports language-specific editor settings.

In your settings.json, you can specify a [language-type] and then set the editor.fontFamily for that type. For *.txt the default and closest [language-type] would be [plaintext].

Here's an example for different fonts for .txt, .json, and .py:

"[plaintext]": {
    "editor.fontFamily": "Chalkduster"
},
"[python]": {
    "editor.fontFamily": "Menlo"
},
"[json]": {
    "editor.fontFamily": "Helvetica"
},

...which gives:

VS Code screenshot of 3 files with different fonts

To check which [language-type] to use for a particular file, open the file, then see the displayed language on the status bar:

VS Code status bar screenshot

Related