简体   繁体   中英

Is there a way to use different Sublime Text themes for different file sources?

I would like to set up two separate themes in ST3. One theme would be for local files, while the second would be for any file opened via my FTP app (Transmit). Is this possible?

The simplest solution may be to override any file coming from the FTP's cache folders. But I have no idea if this is possible.

Yes, this is possible with a fairly simple plugin. Open a new Python file in Sublime, and add the following to it:

import sublime
import sublime_plugin


class TransmitColorSchemeCommand(sublime_plugin.TextCommand):

    def run(self, edit):
        if "/path/to/transmit/tempfiles" in self.view.file_name():
            self.view.settings().set("color_scheme", "Packages/Color Scheme - Default/Monokai.tmTheme")


class TransmitEventListener(sublime_plugin.EventListener):

    def on_load_async(self, view):
        view.run_command("transmit_color_scheme")

Make sure you adjust "/path/to/transmit/tempfiles" to the actual path you want, and change the "color_scheme" setting to the color scheme you want to use for Transmit files. Save the file as Packages/User/transmit_color_scheme.py where Packages is the folder opened when selecting the Preferences -> Browse Packages... menu option. On OS X, it's ~/Library/Application Support/Sublime Text 3/Packages .

Once saved, the event listener will start up immediately, and any file you open that contains the specified path will have the color scheme set to whatever you indicate. All other files from other paths will use your default color scheme.

Have fun!


Please note that this plugin will only work in ST3. To make it work in ST2, change def on_load_async to def on_load .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM