🎁

12 Days of Baddass Courses sale! Get instant access to the entire egghead library of courses and lessons for 58% off.

Runs out in:
13 : 08 : 56 : 20
1×
Become a member
to unlock all features
Autoplay

    Adding Custom Syntax Highlighting to a Theme in VSCode

    Kyle ShevlinKyle Shevlin
    vscodeVS Code

    VSCode Themes are a quick way to update the color scheme and syntax highlighting of your code, but you might find your favorite theme isn't quite perfect. VSCode supports customizations that allow you to fix that problem.

    In this lesson, I add settings to update the syntax highlighting for the Synthwave '84 theme in Markdown and MDX files. We do this by inspecting TM scopes and making custom rules in our settings.json.

    The settings I used are:

    javascript"editor.tokenColorCustomizations": {
      "[SynthWave '84]": {
        "textMateRules": [
          {
            "scope": "markup.inline.raw",
            "settings": {
              "foreground": "#72f1b8",
            }
          },
          {
            "scope": "markup.italic.markdown",
            "settings": {
              "foreground": "#36f9f6",
              "fontStyle": "italic"
            }
          },
        ]
      }
    }
     
    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Discuss

    Discuss

    Transcript

    Transcript

    Instructor: My theme doesn't do all the syntax highlighting that I would really like it to do. How can I update VS Code to let me do that? I noticed that lenses here in italics isn't displayed differently, and neither is view and set that should be code blocks.

    I'm going to start by going to settings.json. I can create something called editor.tokenColorCustomizations. Inside of editor.tokenColorCustomizations, I can specify what theme I want us to go for. In my case, it's SynthWave '84.

    Next, I'm going to need to make some TextMate rules. But which TextMate rules do I make? Going back to my file, I can open up from the command palette Inspect TM Scopes. From here, as I select words, I could see their language, token type, font style, foreground, background, all these things. I can see specifically what scope that they are in.

    We can see that these code blocks are in the markup.inline.raw.string.markdown scope. We'll use some of that to set this. I can see that italics is in markup.italic.markdown.

    Going back to our settings, we can add these rules. We're going to create an object. The first key is scope. We're going to set that to markup.inline.raw. This will be for our little code snippets. We'll add some settings. A foreground of 72F1B8. I'll remove the font style for that one.

    The next one I want to make is for the italics. We'll make another object of scope. This time we'll set it to markup.italic.markdown. We'll set the color to 36F9F6, and the font style to italic. Save our file. If we go back to index.mdx, we now see our italics have updated, and so has our little code snippets.