I have several files that I edit frequently, and I need all of them open at the same time. I am wondering if there is a way in sublime to save a set of files to be open...sort of like how in chrome or firefox I can have a set of web page tabs that I can configured to be open with the click of one button
3 Answers
It won't be like firefox/chrome. What I have seen, Sublime can open your tabs from last time, but it can't open a certain set of tabs automatically.
Open project, open the files you want open next time. Important - When closing Sublime, first choose Project > Close Project, then close Sublime. That will save the open tabs.
Then open each project as thisguy123 describes. Or use the command line option --project path/to/project.sublime-project
.
It is annoying to close each project like this every time so set up a keyboard shortcut:
Save file as ".../Packages/CloseProjectAndExit/close_project_and_exit.py". If you don't know where your Sublime Packages directory is, look at this: http://docs.sublimetext.info/en/sublime-text-3/basic_concepts.html#the-data-directory .
import sublime
import sublime_plugin
class CloseProjectAndExitCommand(sublime_plugin.WindowCommand):
def run(self):
self.window.run_command("close_project")
self.window.run_command("close_window")
Copy to keymap:
{ "keys": ["ctrl+shift+`"], "command": "close_project_and_exit" }
-
It may also be convenient to have key bindings for switching between projects. (see docs.sublimetext.info/en/latest/file_management/…) Dec 29, 2016 at 21:37
-
I'm not sure when it changed, but this is no longer necessary (at least in sublime text 2). Closing the window automatically saves the project. Oct 22, 2017 at 20:09
-
WARNING: In Sublime Text 3, the command
close_project
does not exist. The now equivalent command is calledclose_workspace
. That being said, in the current version of ST3, the built in close window command should now automatically save the project, so this script should not be necessary. Aug 13, 2018 at 17:54
Save it as a project. Project-> Save Project As...
Then when you want to open the tabs again, just go to Project -> Open Project
-
1This didn't work for me. I saved it, and now when I go to project->Open project, I am still looking at a blank sublime editor– KyleDec 4, 2013 at 20:42
-
I now have two files: a 'project' file and a 'workspace' file. The 'project' file only lists some random directory. I see in the 'workspace' file the set of files that I wanted to open. Any idea of what these files should look like?– KyleDec 4, 2013 at 20:46
-
Did you have the files open when you saved your project/workspace? I believe that the workspace file will save what you had open, syntax etc. The tabs that open for me are visible in the "Buffers" section of my workspace file. Dec 4, 2013 at 20:49
-
1
In ST3 Switch Project should replace the current set of tabs with what you last had open on that project.
If it doesn't, that means something is wrong with the project's default workspace.
(solution further down)
Explanation
Sometimes the workspace file gets deleted or something got muddled up, perhaps during directory moves, or issues with files being .gitignored in one branch but not another etc...
From documentation
Projects in Sublime Text are made up of two files: the .sublime-project file, which contains the project definition, and the .sublime-workspace file, which contains user specific data, such as the open files and the modifications to each.
As a general rule, the .sublime-project file would be checked into version control, while the .sublime-workspace file would not.
Another possibility is that you saved a project to a workspace file or vice versa. I think the reason this happens is because it's easy to confuse the two, because when you do Quick Switch Project it shows you both sublime-project files and sublime-workspace files.
Note: The reason it does that is because you're allowed multiple workspaces per project. In Quick Switch Project if you select a workspace, it opens that workspace's project and activates that workspace; if you select a project, it opens that project and activates the project's default workspace, unless it cant find it, in which case it does nothing.
Solution
First do a Save Project As to:
my-project-name.sublime-project
That's just a safety/sanity step. Then Save Workspace As to:
my-project-name.sublime-workspace
Where the file names match. The project will now remember the set of tabs, and switching to will open them.