Sublime Forum

Opening sublime without reopening tabs from previous session

#1

I’ve been able to mostly make sublime suitable for use from the Windows command line (setting it in the EDITOR environment var for tools like git) by using the undocumented --multiinstance flag (see --wait command line option on Windows?). However, if there were tabs open the last sublime was closed, these tabs always get reloaded when sublime launches, which is annoying when you’re just trying to edit a single file. Is there any way to prevent those tabs from reopening?

Maybe the -n command line flag should work that way? If sublime is already running, launching it again with -n opens a new empty window, so it would be consistent to do the same thing when it launches and it’s not already running. Thanks…

0 Likes

#2

You can use the hot_exit and remember_open_files global settings for this

0 Likes

#3

Thanks, yeah that kind of solves it. I think it would still to be nice to able to have remember_open_files set to true, but be able to open a “clean” sublime window via a command line switch (again, -n already does this, except when sublime isn’t already running, which seems inconsistent). I think a lot of users like me like to use editors in two different contexts:

  1. “project” context, where multiple tabs, hot exit, remembering open files, etc. are desired
  2. “single file edit” context, where I want to edit a single file in isolation (usually launched from the command line) and I just want a single window with no other tabs and no hot exit.

Right now I can basically choose between one or the other with global settings, but it would be nice to be able to do both together, using a command line switch for #2. Seems like sublime is really close to supporting that, just not quite there.

Thanks for the great editor!

0 Likes

#4

Actually, I think all of what I described above could accomplished by using a dedicated project for the “single file edit” context, if only sublime would allow setting hot_exit and remember_open_files as per-project settings. Does that make sense? Any chance you could add that feature?

0 Likes

Making ST3 useful as external editor for mailer programs
#5

+1

At the moment I use (g)vim as external editor for my Claws mailer and invoke it with:

gvim "+set ft=mail" -f %s

where “%s” is replaced with the text of email message to be replied/composed.

So, if we’re going to switch to ST2, we’d like to use it everywhere and have need to just launch it in “single file edit” context as described above.

I thought that using --new-window would make it, but, unfortunately, it doesn’t.

Please, provide support for it and you have a new user. :wink:

Sincerely,
Gour

0 Likes

#6

Recently I realized that I do want this feature very much!!!
My use-case is the following:

  • I have a context-menu entry “Edit with Sublime Text”
  • and when I select this menu entry “Edit with Sublime Text” on a single file, I want Sublime Text to open this single file for me, I do not want Sublime Text to open all its previous windows (that I worked with earlier) and only then open my desired single file.

And my question to developers: guys, this question was initially raised 10 years ago!!! Come on, Sublime Text is a paid software and it is not cheap, are you going to provide support for new features?!

0 Likes

#7

You can achieve that by disabling "hot_exit", as described above.

0 Likes

#8

The hot_exit disables the feature globally, whereas I want a local effect similarly to the topic originator. The idea is to introduce a new command line option, e.g. --no-session that will alter Sublime Text’s behavior with regards to hot_exit:

  • when Sublime Text is started without --no-session (e.g. by starting its executable explicitly), it should load its previous files/windows (with hot_exit set to always);
  • when Sublime Text is started with --no-session, it should not load any previous files/windows (i.e. it should behave as if hot_exit was set to disabled, thus overriding the actual value of hot_exit for the instance of Sublime Text that has been started with --no-session);
  • when another instance of Sublime Text is started without --no-session, it should load its previous files/windows (with hot_exit set to always).

To illustrate the idea of a local effect more, let me provide another example.
Sometimes I like to start Sublime Text as a “searcher” by using the following command line:
subl . --command "show_panel {\"panel\": \"find_in_files\", \"pattern\": \"\"}"
It opens an instance of Sublime Text with “Find in files” panel visible. This has a local effect: only this particular instance of Sublime Text is opened with the “Find in files” panel visible, it does not affect the general behavior of any other instance of Sublime Text.
Now, I want to have the very same local effect by specifying e.g.
subl . --no-session --command "show_panel {\"panel\": \"find_in_files\", \"pattern\": \"\"}"
to open only this particular instance of Sublime Text with the “Find in files” panel visible and without loading of the previous files/windows. This should not affect the general behavior of any other instance of Sublime Text.
Do you follow me?

0 Likes

#9

The problem with such an approach is that it breaks a number of features, eg. dragging tabs between windows, quitting not closing all windows, project uniqueness, resource limitations for indexing and find-in-files, shared resources between instances (you double your memory usage for instance) etc.

If those things aren’t a problem for you what you could do is have a separate, portable Sublime Text install that has "hot_exit" disabled.

0 Likes

#10

Thank you for your answer - indeed, complete sandboxing, as you suggested, would help.
I’m thinking would it be possible to achieve the same behavior without the complete sandboxing?
Here is what I mean:

  • the idea of --no-session by its design always applies to a new Sublime Text window. I mean, as we don’t want to load the previous files/windows, the command line of subl --no-session ... is actually equal to opening a new window with the desired file or folder.
  • basing on this, what if subl --no-session ... would create a new window with a property of hot_exit set to disabled for this window? I mean, the concept of hot_exit will not be application-wide, it will be windows-wide, i.e. each Sublime Text window may have different value of hot_exit.
  • now, this window-specific value of hot_exit will be actually applied only during Sublime Text start-up and exiting. During the start-up: if --no-session is specified, then don’t load the previous files/windows and create a new window with its hot_exit property set to disabled. During the exiting: if the window has its hot_exit property set to disabled then nothing from this window is saved to the workspace or whatever.
    What do you think?
0 Likes

#11

I think the concept of hot exit has to be app-wide. Otherwise, if you open ST with --no-session, then open ST as normal and a couple of project windows open, and you quit ST, then what should happen? Should it act like multiinstance, and keep some window(s) open - - thus not really “quitting”, or prompt to save the modified files opened with --no-session, or put those files in the session?

0 Likes

#12

As I’m proposing each Sublime Text’s window to have its own hot_exit property, the behavior can be as simple as that:

  • if Sublime Text is already running without --no-session and there is subl --no-session ... at this point, only the window created by subl --no-session will not be saved on exit (its hot_exit property is set to disabled); all the other windows are saved according to their hot_exit properties.
  • if Sublime Text is already running with --no-session and there is subl ... (without --no-session) at this point, then Sublime Text loads its previous windows/files according to the global hot_exit setting and uses this value of hot_exit to set the hot_exit property for each window that is being created.
0 Likes