Reputation: 6716
I am using the sublime text editor 3 for Linux. I am using it to write Python code. I would like to be able to change the the color of the docstring to another color without changing the color of the regular comment (#
). I have looked in the .tmTheme
file but there is nothing I can find in there about the docstring's color. However there is a theme that clearly has two different colors for the docstring and the regular comment.
How can I modify a theme so that the docstring and the comment are two different colors?
Upvotes: 1
Views: 2060
Reputation: 11
If you want to modify one of the default color schemes you should follow this answer on StackOverflow about installing PackageResourceViewer which will allow you to open the default color scheme and edit it. Once PackageResourceViewer is installed simply press ⌘+Shift+P and search for PackageResourceViewer: Open Resource → Color Scheme - Default → THEME
where THEME
is the theme you want to edit. This will open a .tmTheme
file with all the current settings for that theme. If you want to change any language specific syntax highlighting you need to know the name of that the sublime-syntax file calls the syntax you want to change. The syntax definition files for Sublime Text are hosted on GitHub and show which regular expression is used to define the various syntax for the language. To change the Python language docstring we can look at the Python.sublime-syntax file where it says meta_scope: comment.block.documentation.python
. This means we need to use comment.block.documentation.python
as our scope for the setting in our .tmTheme
file and we can give it any settings we want. So to change the docstring this block of text should be added to your .tmTheme
file:
<dict>
<key>name</key>
<string>Python-Docstring</string>
<key>scope</key>
<string>comment.block.documentation.python</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#FFFFFF</string>
</dict>
</dict>
We designate the name of this style change as Python-Docstring (this field is ignored by Sublime Text), we tell it that we are going to the syntax highlighting for docstrings in python use by setting the scope to comment.block.documentation.python
, and we are changing the settings in that scope to make the foreground text #FFFFFF
. I would recommend saving this file in /Users/USERNAME/Library/Application Support/Sublime Text 3/Packages/User
so that it will be easier to access in the future and doesn't overwrite the default theme. Finally in Sublime Text you go to Sublime Text → Preferences → Color Scheme
and choose you theme!
Upvotes: 1
Reputation: 1
I know this thread is old but i had this same exact issue, couldn't change the color. So this is how it worked for me, i hope it will help somebody. These are the lines i put via the resource viewer:
<dict>
<key>name</key>
<string>docstring</string>
<key>scope</key>
<string>string.quoted.double.block, comment.block.documentation, string.quoted.single.block</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string>italic</string>
<key>foreground</key>
<string>#03FFA7</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>String Quotes</string>
<key>scope</key>
<string>comment.block.documentation punctuation.definition.comment.begin, comment.block.documentation punctuation.definition.comment.end,
,string.quoted punctuation.definition.string.begin, string.quoted punctuation.definition.string.end</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string>italic</string>
<key>foreground</key>
<string>#1FFF0F</string>
</dict>
</dict>
Upvotes: -1
Reputation: 2058
I found this answer which basically recommends you to change an entry in your tmTheme: in the Comment
definition, add the python docstring string.
<dict>
<key>name</key>
<string>Comment</string>
<key>scope</key>
<string>comment, string.quoted.double.block.python</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#757575</string>
</dict>
</dict>
To change your tmTheme easily, PackageResourceViewer (mentioned in the accepted answer in this question) works great.
This will change your docstring to be the same color as the comment. I haven't tested this, but I assume making a new definition like
<dict>
<key>name</key>
<string>Python-Docstring</string>
<key>scope</key>
<string>string.quoted.double.block.python</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#FFFFFF</string>
</dict>
</dict>
will allow you to specify a new color.
Upvotes: 0
Reputation: 102852
I've developed the Neon Color Scheme and the Python Improved language definition to make Python specifically, and as many other languages as possible, look as good as possible, with as many scopes as possible. It also includes different colors for docstrings and comments:
Here are the entries in the .tmTheme
file for docstrings:
<dict>
<key>name</key>
<string>docstring</string>
<key>scope</key>
<string>string.quoted.double.block, string.docstring, string.quoted.single.block</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string>italic</string>
<key>foreground</key>
<string>#218B97</string>
</dict>
</dict>
and regular comments:
<dict>
<key>name</key>
<string>Comment</string>
<key>scope</key>
<string>comment</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string>italic</string>
<key>foreground</key>
<string>#7F817E</string>
</dict>
</dict>
And, if you want to make your quotation marks stand out:
<dict>
<key>name</key>
<string>String Quotes</string>
<key>scope</key>
<string>string.quoted punctuation.definition.string.begin, string.quoted punctuation.definition.string.end</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string>italic</string>
<key>foreground</key>
<string>#FF07A2</string>
</dict>
</dict>
Upvotes: 2