6

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 say I have ColdFusion code and HTML code in the same .cfm file. Could I make the ColdFusion tags red and the HTML tags Blue?

For instance, lets call the below file HelloWorld.cfm - could I colour the tags differently?

<cfset myvar = "hello, world" />
<html>
<head>
  <title>This is my title</title>
</head>
<body>

<div><cfoutput>#myvar#</cfoutput></div>

</body>
</html>

Thanks!

2 Answers 2

22

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.

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

2 Comments

Thanks Jeremy, this is exactly what I'm looking for. Kudos!
@NotJustClarkKent: It would be appropriate then to mark this excellent answer as “the answer” (by clicking on the check-mark).
4

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

1 Comment

Thanks Atomi :) -- I'm playing around with these entity targets now but I fear might be having too much fun ;)

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.