Sublime Forum

How do I change size of comment text but keep other text the same

#1

I add a lot of comments to my code so I was hoping I could change the font size of the comments while keeping other text and code unchanged. I would really appreciate if someone could provide a layman’s guide to achieving this in Sublime Text if it’s possible.

Thank you

0 Likes

#2

Nopes, that’s not possible.

0 Likes

#3

Ok, I was sceptical that it would be but is it possible to change the colour of the comment text?

0 Likes

#4

This document has a section about customisation: https://www.sublimetext.com/docs/3/color_schemes.html

0 Likes

#5

Changing the color of text is possible, as is the style (regular, bold or italic, assuming your font supports it and is monospace). How you do that depends on the color scheme that you’re using.

To clarify, are the comments already colored differently but you want to alter the color that they use, or is all text the same color and you want to make comments different? That is, is the file type Plain text or something else?

0 Likes

#6

Thank you for responding. I’m using a plugin that enables syntax highlighting for shopify liquid files but the colour for the comments is hard to read. I was hoping to make it brighter and smaller.

I’m using a snippet to add the comments. It uses the tags {%- comment -%} and {%- endcomment -%} . I was hoping I could perhaps add some functionality to the snippet that changes the colour and font for the snippet.

0 Likes

#7

What is the value of the color_scheme setting in your user preferences?

0 Likes

#8

“color_scheme”: "Packages/Color Scheme - Default/Mariana.s

I’ve tried other color schemes. The white background is better but i was hoping for a similar color scheme. Just easier to read comments

0 Likes

#9

As @braver mentioned above, you want to refer to the customization section of the color scheme documentation for information on what’s possible w/regards to color scheme customization.

By way of a whirlwind tutorial, in Sublime the syntax of the file that you’re using (in this case Liquid HTML, sounds like) assigns one or more scopes to each part of the file to describe what it is, and your color scheme has a list of rules that associate a scope with a visual style.

In your case, you want to change the color of comments, and by convention comments are generally defined by a scope that starts with comment and gets more specific from there (comment.line, comment.block, comment.block.documentation, etc). So you want a rule that styles the comment scope.

Next, the color scheme you’re using is defined by the color_scheme variable, which as you mentioned above is Mariana.sublime-color-scheme. So you need to make tweaks to that file to alter the colors that you want.

To get started, use the command palette and execute the command View Package File; you’ll be prompted with a list of every file in every package, so enter the text mariana color to filter the list down, and select the file named Color Scheme - Default/Mariana.sublime-color-scheme to open it.

This command opens the file up read-only, so you can’t modify it directly. If you look through the file, you can see that there’s a section with a list of color variables for use later in the file, then some globals that define the global colors for some items, then a list of rules that tell Sublime what colors to use for each scope that should be colored.

The first item in the list is the rule for comments, which looks like this by default:

{
    "name": "Comment",
    "scope": "comment, punctuation.definition.comment",
    "foreground": "var(blue6)"
},

So everything with a scope of comment and a scope of punctuation.definition.comment is set by default to use the color variable blue6, which you can see in the variables section at the top of the file.

To make your modifications, you want to create a file that mimics the structure of this file but contains only the parts that you want to change, then save it as a file with the exact same name, but in your User package. As soon as you save the file, the change will take effect. What happens here is that multiple resources with the same file name are combined together, and the files from your User package are always loaded last, so your changes are applied on top of the defaults.

In your case, a minimal file for changing just the comments rule would look like this:

{
	"rules":
	[
		{
		    "name": "Comment",
		    "scope": "comment, punctuation.definition.comment",
		    "foreground": "var(blue6)"
		},
	]
}

You would enter that content into a file. then save it with the name Mariana.sublime-color-scheme in your User package; if you don’t know where that is, use Preferences > Browse Packages... from the menu to find it.

The above applies a change that has no effect because it’s just the default rule, but you can change that foreground setting to change the color that’s used. See the documentation for the full list of ways to specify a color here. An example would be "foreground": "#FF00FF" to make comments magenta.

Other options include adding a background key to also make the background a different color, and using font_options to apply either bold, italic or bold italic to the color used in order to get things looking like you want, which is presumably not this:

Note that the sublime-color-scheme file is of type JSON, so if the file isn’t valid JSON Sublime will throw an error when you save your file; the message will tell you roughly where the problem is so you can make changes, and the syntax highlighting for the file should show you the general error location as well. The JSON used here is slightly more relaxed than the standard, // comments and trailing commas are allowed.

1 Like