Search code examples
pythonvisual-studio-codecolorscommentssettings

Is it possible to have different color and font settings for comments when they start with # or ## in VS Code?


I want to structure my code better with comments but I want to have different categories for comments, ones that describe the code below and ones that are more personalized for me and include what I want to think of later on, etc..

Is it possible to have different color and font settings for comments that start with # others that start with ## for instance?


Solution

  • Using the Highlight extension, put this into your settings.json:

      "highlight.regexes": {
    
        "(##\\s*)(.*)|(#\\s*)(.*)": {
          "filterLanguageRegex": "python",
          "regexFlags": "gm",
          "decorations": [
            {"color": "yellow"},
            {
              "color": "yellow",
              "backgroundColor": "#f005",
              "fontWeight": "bold",
              "fontStyle": "italic"
            },
            {"color": "orange"},
            {
              "color": "orange"
            }
          ]
        }
      }
    

    There is a lot of styling you can do with this extension, see https://code.visualstudio.com/api/references/vscode-api#DecorationRenderOptions

    python comment highlighting demo