Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any way to change the font family of only commented code in VSCode?

I've come across this in user settings "editor.fontFamily": "Consolas, 'Courier New', monospace", but is there any way to change only the font of comments? I've seen people have semi cursive comments in other editors and I'd like to be able to replicate something similar.

like image 578
Ryan Mcguinn Avatar asked Feb 17 '18 06:02

Ryan Mcguinn


People also ask

Can we change font style in VS Code?

You can select font and color which you want. Show activity on this post. OR press CTRL + , (for windows only) you'll see settings page there find text editor option tab on left side then click on ' Font ' then add any valid font family name there which you want to apply to vscode.


2 Answers

You can change the font style with the editor.tokenColorCustomizations setting:

"editor.tokenColorCustomizations": {
    "textMateRules": [
        {
            "scope": "comment",
            "settings": {
                "fontStyle": "italic"
            }
        }
    ]
}

I don't think there's a way to change the font family right now. The setting only allows customizing fontStyle and foreground (text color). There's an open feature request for adding support for it though:

Support fontName in textMateRules (#36512)

like image 56
Gama11 Avatar answered Oct 02 '22 20:10

Gama11


I had the same issue and it seems you can only make comments italic but cannot change to a separate font. I ended up combining a regular and italic font I liked into a font family which worked.

Download a font editor (FontForge) and create a font family of your own (ex: Custom Font) by changing a regular font you like to Custom Font Regular.ttf and an italic font you like to Custom Font Italic.ttf. Just keep the family name the same.

FontForge Example:

  • Open your desired fonts separately in FontForge.
  • From Element -> Font Info just change
    1. "Fontname" : CustomFont-Regular, CustomFont-Italic
    2. "Family Name" : Custom Font (keep these the same for both)
    3. "Name For Humans" : Custom Font Regular, Custom Font Italic
    4. Don't touch anything else and hit OK.
    5. Accept if/when it asks to change ID
    6. File -> Generate Font as True Type
    7. Install your newly named ttf fonts
    8. Then add your new family to vs code. (If you're following along that's "Custom Font")

Pretty straightforward and works great in VS Code. Hope this helps somebody

like image 33
Jeff Avatar answered Oct 02 '22 18:10

Jeff