I posted this on another thread, but I wanted to make sure that it is here as well. This thread is one of the top search results for exactly what you’re asking about. The answer below about using the XML configuration file is a bit dated. Here is an updated set of instructions for setting the highlighting back to what you expect (or to change it to something totally different, if that’s what you like).
Instructions
If one wants to change this behavior without digging into and modifying the default syntax and color scheme, just customize the color scheme. Sublime has its own configuration file and syntax for that. No need to use .tmTheme
. Just go to the Sublime Text menu and select Preferences then “Customize Color Scheme”. This reveals an editor showing the default settings for the color scheme on the left and an empty user color scheme on the right.
To change how docstrings are highlighted, just add an entry to the list of rules
. The following will change the docstrings to look like all other strings. Some people prefer this. You can also change the color that it uses by looking at the list of available colors in variables
in the default color scheme. You may pick any of those colors to suit you. If you don’t like those colors, you can add a new color to the user color scheme variables
. You would then choose a variable name that is not already used and then define a color there. That variable name would then be entered in the foreground
field of your custom rule.
"rules":
[
{
"name": "Docstrings",
"scope": "comment.block.documentation.python",
"foreground": "var(yellow)"
}
]
Note: I am using Monokai color scheme in this example, but you can use whichever one you like, the variable you use in the foreground
field may then be different.
To access the default syntax definitions, open the command palette, and run “View Package File”. In the next popup, type “Python/” to view the contents of the default Python package. You will see “Python/Python-sublime-syntax” listed. Select it and you will then have the file with all the scopes that you need open in a new tab. (Updated from previous; thanks @FichteFoll)
Middle Ground
If you want to have docstrings that are still “commenty” but also different than other comments, I add a new color called grellow
to the user variables
like so.
"variables":
{
"grellow": "hsl(60, 60%, 30%)"
},
You would then change the foreground
field in the rules
definition to var(grellow)
.