Sublime Forum

How to define different colours for Single and Double quoted strings

#1

I’m a new user of Sublime Text 3, having finally given up with Notepad++.

I’ve installed the Oracle PL/SQL package to help with some XML DB development.

The issue I have is that some of the literal strings need to be single quoted and others need to be double quoted.

For example,

SELECT
XMLelement(“BusinessType”, ‘B74’)
FROM dual;

In ST3, both single and double quoted strings are displayed in the same colour, yellow.

I’ve got pages and pages of Oracle XML queries to sift through and it would be hugely convenient to have single and double quoted strings displayed in different colours.

At the moment all strings are in yellow.

I couldn’t see how to set this in the PL/XML package.

I found the following configuration in the Monokai.sublime-color-scheme settings.

{
“name”: “String”,
“scope”: “string”,
“foreground”: “var(yellow)”
},

Is it possible to distinguish between single and double quoted strings, and if so, can they be set to different colours?

0 Likes

#2

Since the original post, I’ve installed PackageResourceViewer and opened the file “PL SQL (Oracle).tmLanguage”.

I found these sections in there that look promising

    <dict>
        <key>begin</key>
        <string>'</string>
        <key>end</key>
        <string>'</string>
        <key>name</key>
        <string>string.quoted.single.oracle</string>
    </dict>
    <dict>
        <key>begin</key>
        <string>"</string>
        <key>end</key>
        <string>"</string>
        <key>name</key>
        <string>string.quoted.double.oracle</string>
    </dict>

I tried adding the following lines to the double quoted string settings.

        <key>foreground</key>
        <string>#6ad612</string>

This now looks like

    <dict>
        <key>begin</key>
        <string>"</string>
        <key>end</key>
        <string>"</string>
        <key>name</key>
        <string>string.quoted.double.oracle</string>
        <key>foreground</key>
        <string>#6ad612</string>
    </dict>

It still doesn’t work, but I feel I’m almost there…

0 Likes

#3

You are not supposed to modify the syntax but your color scheme.
Basically you have found that the two string have a different scope: string.quoted.double and string.quoted.single

Just update your color scheme with those scopes:

{
"name": "String single",
"scope": "string.quoted.single",
"foreground": "var(green)"
},
{
"name": "String double",
"scope": "string.quoted.double",
"foreground": "var(yellow)"
},
2 Likes

#4

It works!

In fact, I’ve been a bit more specific and used the scope “source.plsql.oracle string.quoted.single.oracle”.

Now it only applies the colour to single quoted strings in PL SQL.

Thanks!

3 Likes