Change / Add syntax highlighting for a language in Sublime 2/3

后端 未结 5 658
深忆病人
深忆病人 2020-12-07 13:21

I want to change / add syntax highlighting for a language in Sublime 2/3.

For example I want the keyword this colored in JavaScript.

How can I d

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-07 13:42

    This is my recipe

    Note: This isn't exactly what OP is asking. These instructions will help you change the colors of items (comments, keywords, etc) that are defined syntax matching rules. For example, use these instructions to change so that all code comments are colored blue instead of green.

    I believe the OP is asking how to define this as an item to be colored when found in a JavaScript source file.

    1. Install Package: PackageResourceViewer

    2. Ctrl+Shift+P > [PackageResourceViewer: Open Resource] > [Color Scheme - Default] > [Marina.sublime-color-scheme] (or whichever color scheme you use)

    3. The above command will open a new tab to the file "Marina.sublime-color-scheme".

      • For me, this file was located in my roaming profile %appdata% (C:\Users\walter\AppData\Roaming\Sublime Text 3\Packages\Color Scheme - Default\) .
      • However, if I browse to that path in Windows Explorer, [Color Scheme - Default] is not of a child-dir of [Packages] dir. I suspect that PackageResourceViewer is doing some virtualization.

    optional step: On the new color-scheme tab: Ctrl+Shift+P > [Set Syntax: JSON]

    1. Search for the rule you want to change. I wanted to make comments be move visible, so I searched for "Comment"

      • I found it in the "rules" section
     "rules":
        [
            {
                "name": "Comment",
                "scope": "comment, punctuation.definition.comment",
                "foreground": "var(blue6)"
            },
    
    1. Search for the string "blue6": to find the color variable definitions section. I found it in the "variables" section.

    2. Pick a new color using a tool like http://hslpicker.com/ .

    3. Either define a new color variable, or overwrite the color setting for blue6.

      • Warning: overwriting blue6 will affect all other text-elements in that color scheme which also use blue6 ("Punctuation" "Accessor").
    4. Save your file, the changes will be applied instantly to any open files/tabs.

    NOTES

    Sublime will handle any of these color styles. Possibly more.

    hsla = hue, saturation, lightness, alpha rgba = red, green, blue, alpha

    hsla(151, 100%, 41%, 1) - last param is the alpha level (transparency) 1 = opaque, 0.5 = half-transparent, 0 = full-transparent

    hsl(151, 100%, 41%) - no alpha channel

    rgba(0, 209, 108, 1) - rgb with an alpha channel

    rgb(0, 209, 108) - no alpha channel

提交回复
热议问题