Syntax specific highlighting with Sublime Text 2

后端 未结 2 862
心在旅途
心在旅途 2021-01-13 07:54

I\'m wondering if there is a way to have two different tag colours (\"colors\" for those in the US) for different language tags in the same file.

For example, lets s

相关标签:
2条回答
  • 2021-01-13 08:18

    Yes, as long as the tags can be identified as having different scopes by your installed language definitions, you can edit your colour scheme to target those scopes with specific colours and other styles.

    In your packages folder, language scopes are defined in the .tmLanguage files for your installed languages, while styles are defined in the .tmTheme files in the "color scheme - default" folder.

    If you position your cursor inside a tag, and press shift+ctrl+alt+p (shift-cmd-p in OSX I think) the status bar will display the current scope. You can also copy this to the clipboard via the console with this command:

    sublime.set_clipboard(view.syntax_name(view.sel()[0].b))
    

    You can use this information to create your styles, a bit like css selectors, but with XML. For example I use this Coldfusion package and I have the scope selectors shown below in my custom .tmTheme file to distinguish cf tags from HTML tags.

    <dict>
        <key>name</key>
        <string>Tag name</string>
        <key>scope</key>
        <string>entity.name.tag</string>
        <key>settings</key>
        <dict>
            <key>background</key>
            <string>#D8D0B6</string>
            <key>fontStyle</key>
            <string>bold</string>
            <key>foreground</key>
            <string>#647A4F</string>
        </dict>
    </dict>
    <dict>
        <key>name</key>
        <string>CF tag name</string>
        <key>scope</key>
        <string>entity.name.tag.conditional.cfml, entity.name.tag.declaration.cfml, entity.name.tag.other, entity.name.tag.cf, entity.name.tag.inline.other.cfml</string>
        <key>settings</key>
        <dict>
            <key>background</key>
            <string>#D8D0B6</string>
            <key>fontStyle</key>
            <string>bold</string>
            <key>foreground</key>
            <string>#990033</string>
        </dict>
    </dict>
    

    More info on scope selectors.

    0 讨论(0)
  • 2021-01-13 08:31

    I've updated the ColdFusion.tmLanguage so that you'll only need to target entity.name.tag.cf to color all cf tags. You can also target specific tags for example entity.name.tag.cf.script or entity.name.tag.cf.query for cfscript and cfquery respectively. HTH

    0 讨论(0)
提交回复
热议问题