Sublime Forum

Change the bg of comments

#1

Hello.

I want to change the background color of the comments (//,#,/**/) but I don’t know how to do it.

Could you help me please?

Thanks!

0 Likes

Discriminate the comments syntax // and /**/ in c++
#2

You will need to edit the color scheme you are using.

You can find the default one in the install directory (typically Program Files\Sublime Text3 for windows), inside packages\Color Scheme -Default.sublime-package : this file a zip, you can unzip somewhere.
Copy the color Scheme of you choice in your user package directory (ctrl+shift+p “Browse Package” to open an explorer to the correct directory): here you can create a directory “Color Scheme - User” and copy your color scheme.

Now you can finally edit it: to get what you want, search something like “scope comment”
You should see under something like foreground with an hex value for the font color.
Just add under foreground#000000 (replace 000000 by the color you want)

0 Likes

#3

Great!
Works perfect!

The only problem is that there’s no difference among the different types of comments. I would like to difference the styles depending on the coment type: single line comment (//,#), multiline comment (/* */, ) and so on.

Is this possible?

Thank you so much!

0 Likes

#4

Yes, but it will depend of the syntax file used.
Open a file, put your cursor on a comment and press ctrl+alt+shift+p : in the status bar the scope will be displayed. Typically you should get something starting with comment. If the syntax is well done you will get different scope value for different type of comment: typically i have seen comment.line for single line comment and comment.block for multi-line comment.
You can now define a color specific to this scopes, in addition to the one already exisiting for just comment: this way if comment.line or comment.block is not used by your syntax file it will fall back to the more global comment one.

Here is what you should add (just change fontstyle and foreground setting)

		<dict>
			<key>name</key>
			<string>Comment Single Line</string>
			<key>scope</key>
			<string>comment.line</string>
			<key>settings</key>
			<dict>
				<key>fontStyle</key>
				<string>italic</string>
				<key>foreground</key>
				<string>#75715E</string>
			</dict>
		</dict>
		<dict>
			<key>name</key>
			<string>Comment Mult-Line</string>
			<key>scope</key>
			<string>comment.block</string>
			<key>settings</key>
			<dict>
				<key>fontStyle</key>
				<string>italic</string>
				<key>foreground</key>
				<string>#75715E</string>
			</dict>
		</dict>
0 Likes

#5

Just perfect.
Thanks so so much Clams! :wink:

0 Likes

#6

Thanks for this - I have been looking everywhere for a description of how to distinguish the two different comment styles!

0 Likes