4

I am interested in giving lectures and taking notes in simple text files within VSCode (since I already use it for coding).

However, for the life of me I cannot figure out how to change simple text color. What I want is to have one text color at one indentation depth. For instance,

Notes:
    a:
    b:

Notes would be a different color than a and b. I want this for clarity of bullet points. Is there a simple way?

Thanks.

0

2 Answers 2

5

You can color lines with different indentation differently with an extension like Highlight. For instance I can get this:

demo of Highlight extension

with this code in settings.json:

"highlight.regexes": {

  "((?<!.))(\\w.*)": [
    {},
    {
      "color": "green",
      "fontWeight": "bold",
      // "outline": "1px solid #fff",
      "letterSpacing": "1px"
    }
  ],
  "((?<!.))(  )(\\w.*)": [
    {},
    {},
    {
      "color": "yellow",
    }
  ],
  "((?<!.))(    )(\\w.*)": [
    {},
    {},
    {
      "color": "red",
    }
  ]
}

My setup inserts 2 spaces per tab - I found that you need to use spaces in your regex, not something handier like (\\t\\t) or ( ){4} but instead must use ( ) - that is 4 spaces representing two tabs for me - for the regex to work in the extension.

For more styling options, see https://code.visualstudio.com/api/references/vscode-api#DecorationRenderOptions

The extension link shows how to restrict this to whichever filetype(s) you wish. Which I incorporated into the second batch of code below.

If you want only the bullet headings, like a-z or 1-9 to be colored and not the rest of the text on that line, that can be achieved in the regex too:

"highlight.regexes": {

  "((?<!.))(\\w.*)": { 
    "regexFlags": "gi", 
    // "filterLanguageRegex": "markdown", 
    "filterFileRegex": "Notes.*\\.txt", 
    "decorations": [
      {}, 
      { 
        "color": "green",
        "fontWeight": "bold",
        "letterSpacing": "1px",
        "textDecoration": "underline"
      },
    ]
  },


  "((?<!.))(  )([a-z1-9][:\\.])(.*)":  {
    "regexFlags": "gi", 
    // "filterLanguageRegex": "markdown", 
    "filterFileRegex": "Notes.*\\.txt", 
    "decorations": [
      {},
      {},
      {
        "color": "yellow",
      },
      {}
    ]
  },


  "((?<!.))(    )([a-z1-9][:\\.])(.*)": {
    "regexFlags": "gi", 
    // "filterLanguageRegex": "markdown", 
    "filterFileRegex": "Notes.*\\.txt", 
    "decorations": [
      {},
      {},
      {
        "color": "red",
      },
      {}
    ]
  }

[Restricted to files of the form Notes1.txt, Notes blsdfs .txt and similar.]

demo 2 of Highlight extension

Obviously, you can have as many levels of indentation as you want with more regex entries following the same pattern.

Sign up to request clarification or add additional context in comments.

Comments

-1

Syntax highlighting is not related to indentation, but rather tokens and scopes.

From Syntax Highlight Guide:

VS Code uses TextMate grammars to break text into a list of tokens. TextMate grammars are a structured collection of Oniguruma regular expressions and are typically written as a plist or JSON. You can find a good introduction to TextMate grammars here, and you can take a look at existing TextMate grammars to learn more about how they work

Many folks take notes in Markdown, which offers syntax highlighting and formatting. Maybe give that a try?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.