Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change background color of Sublime Text 3?

I am using Sublime Text 3 Build 3154. I am currently using Material Theme UI Darker. The problem is I don't know to make the background color (the area where we code) a bit darker. Please help me how can I do this? I enabled contrast mode for sidebar, status bar and title bar. I want to make the background color of where we code the same as contrast mode. Please help.

Settings of my Sublime Text 3:

{
    "always_show_minimap_viewport": true,
    "background": "red",
    "bold_folder_labels": true,
    "color_scheme": "Packages/Material Theme/schemes/Material-Theme-Darker.tmTheme",
    "font_size": 16,
    "highlight_line": true,
    "ignored_packages":
    [
        "Material Theme - Appbar",
        "Theme - Dark Material",
        "Vintage"
    ],
    "indent_guide_options":
    [
        "draw_normal",
        "draw_active"
    ],
    "line_padding_bottom": 7,
    "line_padding_top": 7,
    "material_theme_accent_scrollbars": true,
    "material_theme_accent_yellow": true,
    "material_theme_big_fileicons": true,
    "material_theme_bold_tab": true,
    "material_theme_bullet_tree_indicator": true,
    "material_theme_contrast_mode": true,
    "material_theme_small_statusbar": true,
    "overlay_scroll_bars": "enabled",
    "theme": "Material-Theme-Darker.sublime-theme"
}

Please Help me. I am using latest version of Material Theme

like image 354
Sanjay Avatar asked Dec 23 '22 11:12

Sanjay


1 Answers

The Theme that you're using modifies the overall look of the UI, which includes things like the sidebar, status bar, tab shape, and so on. At any one time there can only ever be one Theme active, since it is application wide.

In contrast, colors used in inside of the views used to edit files are controlled by a Color Scheme. Unlike Themes, the color scheme can be modified in a tab-by-tab or file-by-file basis.

So in order to change the background color of a file editing view, you need to make changes to the color scheme that you're using.

The color scheme that is in use is set by the color_scheme setting, which you can see by selecting Preferences > Settings from the menu (Preferences is under Sublime Text in the menu on MacOS).

If you have a custom color scheme set, you will see it in the right hand pane of this window; otherwise your color scheme is the default, which you will find in the left hand pane.

According to your post, the color scheme that is currently in use is "Packages/Material Theme/schemes/Material-Theme-Darker.tmTheme".

This is telling you that the file that needs to be altered is Material-Theme-Darker.tmTheme, and it is contained inside the Material Theme package in a folder named schemes.

How you make the change you desire depends on the extension of the file mentioned in the color_scheme setting, which itself also depends on the build of Sublime Text 3 that you're currently using and the author of the theme itself.

Extension is tmTheme


Files of type tmTheme are XML formatted files based on the Plist file format from MacOS. This is the "classic" or "legacy" color scheme format used in Sublime Text; it's inherited from TextMate. In order to modify colors in these files, you need to modify the file itself, which requires you to first open the file.

Files in Sublime packages are generally compressed into sublime-package files, which requires you to create an override for the file to get Sublime to ignore the version in the package and use yours instead.

Occasionally a package may be installed "Unpacked" as a set of files inside of the Packages folder. The following instructions will work regardless of how the theme that you're using is installed.

The first step is to open the file that you want to modify. The easiest way to do that is to use PackageResourceViewer (install it first if you're not already using it):

  1. Open the command palette and select the PackageResourceViewer: Open Resource command by entering prvor to filter the list
  2. Select the package that contains the theme (here Material Theme)
  3. Select the file that you want to open (here select schemes, then Material-Theme-Darker.tmTheme

This opens the file, and what you're seeing is the file that Sublime is currently using as your color scheme. Any modifications you make to this file will immediately take effect on the color scheme that you're sing.

Generally speaking you would edit the contents of this file as appropriate to apply any color(s) that you want. In your case you want to modify the background color of the text area, so near the top of the file you're going to see a section that looks somewhat like this (this is from the default Monokai color scheme):

<key>settings</key>
<dict>
    <key>background</key>
    <string>#272822</string>
    <key>caret</key>
    <string>#F8F8F0</string>
    <key>foreground</key>
    <string>#F8F8F2</string>
    <key>invisibles</key>
    <string>#3B3A32</string>
    <key>lineHighlight</key>
    <string>#3E3D32</string>
    <key>selection</key>
    <string>#49483E</string>
    <key>findHighlight</key>
    <string>#FFE792</string>
    <key>findHighlightForeground</key>
    <string>#000000</string>
    <key>selectionBorder</key>
    <string>#222218</string>
    <key>activeGuide</key>
    <string>#9D550FB0</string>
    <key>misspelling</key>
    <string>#F92672</string>
    <key>bracketsForeground</key>
    <string>#F8F8F2A5</string>
    <key>bracketsOptions</key>
    <string>underline</string>
    <key>bracketContentsForeground</key>
    <string>#F8F8F2A5</string>
    <key>bracketContentsOptions</key>
    <string>underline</string>
    <key>tagsOptions</key>
    <string>stippled_underline</string>
</dict>

This sets various global colors for the color scheme. The rest of the file is for applying specific colors to the contents of files based on the syntax of the language that you're viewing.

In your case you want to modify the background color, so modify the value of the background property to the color that you want. For you, that would look like this:

<key>background</key>
<string>#1a1a1a</string>

As soon as you save the file, you should see the change immediately take effect in all of your open files.

When you save, if the file was a part of a sublime-package file, an override wil be created for this file, which will be used instead of the version in the sublime-package file.

When that happens, your override will always be in effect even if the package author updates the color scheme. Sublime won't tell you that this is happening.

The OverrideAudit package will give you warnings when this happens to you, so you can handle the situation by changing your file to match the new one or removing it altogether, if you're concerned about this.

Extension is sublime-color-scheme


Files of this type are a new type of color scheme format that is JSON based instead of XML based.

At the present time (January 8, 2018) color schemes of this format are only available in development builds, but at some point in the future they will become the new file format for color schemes going forward.

Like most Sublime resources, files of this type are additive; all resources with the same name from all packages are loaded and combined together at run time.

In order to see what you need to modify here, open the Command Palette and select the View Package File command by by entering vpf to filter the command list, then select the appropriate package file from the list presented, which lists all package files in the same format as the color_scheme setting.

Note: This command is only present in recent development versions of Sublime, so you won't see it if you're using an older build; I would assume in that case you also won't see color schemes in this format, but just in case you can also use the PackageResourceViewer steps from above to look at the file.

This time the file that you see is a JSON interpretation of the same data. Again, here is a relevant section near the top of the file, where this example is the default Monokai color scheme. Make sure that you DO NOT save this file, just take a look at it.

"globals":
{
    "foreground": "var(white3)",
    "background": "var(black3)",
    "caret": "var(white2)",
    "invisibles": "color(var(white3) alpha(0.35))",
    "line_highlight": "var(yellow4)",
    "selection": "var(grey)",
    "selection_border": "var(black2)",
    "misspelling": "var(red2)",
    "active_guide": "color(var(orange2) alpha(0.69))",
    "find_highlight_foreground": "var(black)",
    "find_highlight": "var(orange3)",
    "brackets_options": "underline",
    "brackets_foreground": "color(var(white3) alpha(0.65))",
    "bracket_contents_options": "underline",
    "bracket_contents_foreground": "color(var(white3) alpha(0.65))",
    "tags_options": "stippled_underline"
},

In this example, most of the colors are coming from a variables section just above, which allows you to easily change a color and have its representation change everywhere that the variable is referenced.

In order to alter items in a file of type sublime-color-scheme, instead of saving this file, you create a new file in your User package that has the same name, and include in it only those parts of the color scheme that you want to change.

In our example here, you would do that be creating a file with the following contents and saving it in your User package as Material-Theme-Darker.sublime-color-scheme.

{
    "globals":
    {
        "background": "rgb(26,26,26)"
    }
}

As above, as soon as you save this file, you should see the color change.

This file is combined with the default file that we were looking at, but here we just provide a background color and the rest of the content is taken from the original.

This version of the file (and thus your background color change) will always take effect when this color scheme is active, regardless of what the underlying color scheme thinks the background color should be.

like image 186
OdatNurd Avatar answered Jan 08 '23 19:01

OdatNurd