Sublime Forum

Bring window to foreground instead of opening new one?

#1

Hi,

I was wondering if, when running subl on the command line, there is any way to tell Sublime to not open a new window if I already have a window open for , and instead just bring that window to foreground.

In case my question doesn’t make any sense, my use case is this: I typically have a few Sublime windows open (around 5) and sometimes I just need to find a specific window.
I can Alt+Tab to find the right window, but running subl is much faster, because I probably also already have a shell open for this same that I’m working on.

I’m using Sublime on Ubuntu (15.04 Vivid), so maybe if Sublime can’t help me here but there is a way to achieve this via scripting, I’d also like to know!

Thank you :smile:

0 Likes

Subl opens files in wrong window, always opens directories in new window
#2

Yep! Pass the -a flag, and it will add it to the currently open window.

So:

subl scripts.js -a
0 Likes

#3

That’s not quite what debora is looking for, I think.
I’m not sure if it’s possible to do what you want.

0 Likes

#4

Hi,

Yes, @adzenith is right: I’m not looking to add a file to the current window, but to “reuse a window”, so to speak.

Example:

# Start with no open Sublime windows at all.

# This will open a new window, with ~/Documents as the root folder.
subl ~/Documents

# Now run the same command again: it will open yet another window,
# again with ~/Documents as the root folder.
subl ~/Documents

The question is: when I run the second command, could I have Sublime (or the window manager in my OS) just show me the first window that I opened, instead of opening a new one?

Thanks for the suggestion, though, @wesbos!

0 Likes

#5

I imagine Jon would need to code a -find_window_if_exists command line option. In which case, if a directory is supplied as the parameter, the first Sublime window which has that directory open is shown, or in the case of a file, the first window containing that file in a tab with the tab activated.

I’m wondering if this could be done with a plugin. Subl has the --command switch which can be used to run, presumably, any type of command. If parameters can be passed to the command via the command line, it’s feasible for a plugin to find the corresponding window (or tab) and activate it?

As an aside (OT and just an opinion) Sublime’s current command line behaviour leaves stuff to be desired at present. Apart from a number of little bugs (eg. new blank windows sometime appearing and sometimes not when launching subl with the --project switch) it would be really useful to be able to launch new “incognito” sublime process(s) entirely isolated from the main sublime process, ignoring any hot_exit/previous project/tabs etc, and with any state saving features on exit disabled. This would make sublime much more usable as a go-to command line editor a la vim, plus it allows for sublime to be run elevated (sudo etc), even if the existing sublime process is run in user context (a regular PITA for me). It means that the main sublime “app” could be left open with projects etc, while incognito sublimes can be run at will for ad-hoc editing. Also, it means that if sublime is not running, it could be run for ad-hoc editing without touching the state, projects and tabs of the main sublime app.

:smile:

0 Likes

#6

I second that entire last paragraph.

0 Likes

#7

Totally agree with that, and I would also really appreciate the ability to pass arguments to commands via cli.

0 Likes

#8

Still looking for this feature.

For reference, TextMate’s ‘mate’ command has had this functionality for as long as I’ve used it.
I’d rather use Sublime, but I work with a lot of windows open, and I’m not fond of hunting for the exact window when I already have a terminal window in the correct directory.

1 Like