jokoon
jokoon

Reputation: 6653

Change operator color in sublime text?

In notepad ++ I can change the color of special characters like "!@#$%^&*(){}[].

Is this possible with sublime text ? I know it uses textmate theme files, but I don't know what I should edit...

Any idea ?

PS: I mostly use C++ syntax

Upvotes: 3

Views: 1842

Answers (2)

Adrian
Adrian

Reputation: 2365

It appears that operators are not listed in Sublime Text's C++ language file, so I think you need to add them first.

To the file %SUBLIMEDIR% / Packages / C++.sublime-package / C++.tmLanguage add the following:

<dict>
    <key>match</key>
    <string>\=|\+|\-|\*|\%|\+\+|\-\-|\=\=|\!\=|&lt;|&gt;|&lt;\=|&gt;\=|\!|&amp;&amp;|\|\||\~|&amp;|\||\^|&lt;lt;|&gt;&gt;|\+\=|\-\=|\*\=|/\=|\%\=|&amp;\=|\|\=|\^\=|&lt;&lt;\=|&gt;&gt;\=|\[|\]|\(|\)|\-&gt;|\-&gt;\*|\.|\.\*|\?|\:|\:\:</string>
    <key>name</key>
    <string>keyword.operator</string>
</dict>

...in the region where similar entries are being made. That should cover most C++ operators.

Afterwards the edit suggested by Protractor Ninja should take effect. I haven't thoroughly tested this though, a sophisticated regex might be better.

Upvotes: 1

angerson
angerson

Reputation: 7402

I'm a tad late, but to change operator color in Sublime Text, you'll have to edit your color scheme file (.tmTheme filetype). As long as the language definition for the language you're using is written in such a way that the symbols you want are classified as operators, this ought to do the trick.

Add the following code to the end of your current .tmTheme file (located in Packages/Color Scheme - Default/ if you're using one of the defaults; others will be either in their own subdirectory or in Packages/User/), just before the final </array> tag:

<!-- Custom operator colors -->
<dict>
    <key>name</key>
    <string>Custom Operator Colors</string>
    <key>scope</key>
    <string>keyword.operator</string>
    <key>settings</key>
    <dict>
        <key>foreground</key>
        <!-- Your hexadecimal color code here -->
        <string>#FFFFFF</string>
    </dict>
</dict>

That will colorize code categorized as keyword.operator (based on the TextMate naming conventions) with whatever color value you desire. This solution will hold for all languages, as long as you use the same color scheme.

Upvotes: 2

Related Questions