Is there any way that I can set Sublime Text 2 to always open a particular file by default?

466 views Asked by At

I would like Sublime Text to open my scratchpad by default, is there any way to facilitate this?

2

There are 2 answers

0
skuroda On

Might be something better, but you can use something like this.

import sublime

VERSION = int(sublime.version())

def open_default_file():
    settings = sublime.load_settings("Preferences.sublime-settings")
    if settings.has("default_file"):
        sublime.active_window().open_file(settings.get("default_file"))
    else:
        scratch_name = "Scratch Space"
        found = False
        window = sublime.active_window()
        views = window.views()
        for view in views:
            if view.name() == scratch_name and view.file_name() == None:
                found = True
                window.focus_view(view)
                break

        if not found:
            view = sublime.active_window().new_file()
            view.set_scratch(True)
            view.set_name("Scratch Space")

If you want a specific file opened, you can specify a file (as a string) in Preferences.sublime-settings using the key default_file. If you just want a general scratch file, you don't have to add anything.

0
Anunay Inuganti On

I've made a plugin for this:

https://packagecontrol.io/packages/Scratchpad

Presently there is no option to choose the location of the file, will consider adding it if required.