sublime_text
sublime_text copied to clipboard
[Linux] Open file should use sublime instance from current virtual desktop
Summary
Opening a file via command line subl file.md
or via file browser opens the file in the last used sublime instance which might be located on another desktop in a virtual desktop environment of Linux such as Openbox.
Expected behavior
Opening a file via
- command line (
subl file.md
) - file browser
- (CTRL-Left Mouse in a PDF created with LaTeXTools and Synctex)
should open the respective file in
- a sublime instance located on the current virtual desktop
- (potentially create a new sublime instance if none is existent on the current virtual desktop. From commandline you can already use
subl -n file.md
for that)
Actual behavior
The file appears in the recently used sublime instance that might be on a different virtual desktop. This behavior is cumbersome, because you have to find the particular instance, or click the instance on the current virtual desktop and reopen the file.
Steps to reproduce
- Open two sublime instances on virtual desktops A and B
- Focus sublime on desktop A
- Go to desktop B without focusing sublime
- Open file for sublime via e.g. your file browser
- The file will be opened on desktop A
Environment
- Operating system and version:
- Linux: Lubuntu 16.10 with LXDE and Openbox (but should be applicable to all environments using virtual desktops)
- Sublime Text:
- Build 3143 (most likely not limited to this build)
- 64 bit
Related issues are:
- for Windows: #1773
- for OS X: #333
Also #2267
Also this happens on Ubuntu 18.04.
I switched to Visual Code due to this bug.
Is there any update on this bug?
No, but I also don't know how fixable this is. I'm not aware of a generally standardized API between various window managers on Linux and since you have the choice between many, you'd either end up having to hardcode workarounds for the most common window managers (probably at least those from entire desktop environments like Gnome and KDE).
The other option would be to write a short (shell) script that interfaces with the WM's API to determine whether there is an ST window in the current virtual desktop and, depending on whether that is the case, add or remove the -n
flag from the subl
call. However, you cannot choose which window to open a file in from, so that would be a feature that needs to be added to the CLI. Or you write a custom command in a plugin that handles this lookup for now and that you call from the command line.
No, but I also don't know how fixable this is. I'm not aware of a generally standardized API [...]
Yeah, I don't know how other applications do it, but I know many of them do. The one that comes to mind immediately is Chrome, but with a huge dev team an Google money, I'd believe it if someone told me they just wrote a fix for every Linux window manager they could find.
Any updates? This issue is quite bothersome. I am finding myself increasingly using gedit for "quick edits" to avoid having to look through N workspaces for the latest Sublime window.
This issue is annoying and bothering the user on Linux. Please consider it seriously and fix it. I'm thinking about VS code because of this bug.
I want to echo the same concern, this is really annoying because it causes a sudden mental context switch that comes with workspace switch. physically this is equivalent to picking up an object an suddenly finding yourself in a different room so you forget what is it I wanted to do in first place. I am a paid customer but often find myself using geany or something else to avoid this. you guys need to fix this.
I want to echo the same concern, this is really annoying because it causes a sudden mental context switch that comes with workspace switch. physically this is equivalent to picking up an object an suddenly finding yourself in a different room so you forget what is it I wanted to do in first place. I am a paid customer but often find myself using geany or something else to avoid this. you guys need to fix this.
I agreed with you. I bought Sublime and now I regret about this. This is a simple thing to fix and if the developer do not want to fix that, they are going to lose customer.
I've written https://github.com/tsantzi/launch_sublime to help me with this. Only tested under Linux/Cinnamon, but should be easy to adapt. Needs wmctrl
installed.
I did not have this problem on my Kubuntu laptop until I had to reformat & reinstall. So why did it occur? What did I have that made it work without this problem before? The only thing I can think of is I was using a different task switcher. I changed it back to 'Thumbnails', like my original install and now when I open Sublime, it opens in the background on the current workspace. Switching back to 'Breeze' task switcher does not cause the problem to recur. So I'm not clear what I've done to fix it. But I had the problem you are reporting, and I was able to get it to disappear by changing my task switcher.
Not sure if this helps at all.
@tsantzi 's script works for me (Ubuntu 20.04), but I agree this should be fixed in subl itself. If it requires some WM-specific code, then that's probably just the cost of doing business on a particular OS. Although I sympathize with how annoying this would be to maintain for Ubuntu in particular, where Canonical seems unable to break the habit of throwing out major components of their windowing stack every couple versions.
Ah, no, I spoke too soon. It seems that, even with ps aux | grep subl
returning no results, subl -n
(or /opt/sublime_text/sublime_text --new-window
) insists on opening on a different desktop than the one I'm testing from. There's really no excuse for this; there's no previous instance to be confused with.
I can fix it temporarily by deleting or renaming ~/.config/sublime-text/Local/Session.sublime_session
. It's not a great solution, but if you don't care about "session"s, you can just add rm $HOME/.config/sublime-text/Local/Session.sublime_session
to the script from @tsantzi . At this point, I just use sublime as a basic editor, and VSC for anything serious, so I'm fine with that.
A more fine-grained approach might be to parse that file (it's JSON) and strip out some sort of workspace information, but how to do this minimally without losing things like my menu-hide preference (why isn't this in ~/.config/sublime-text-Packages/User/Preferences.sublime-settings
instead, BTW?) would take me more than 0 minutes of effort, so I'm going with the brute-force method now.
Hi @tsbertalan, yes, this weird behaviour of subl -n
jumping to another workspace started happening on my system too, a few months ago. Note that it only happens sometimes/rarely (at least on Arch+Cinnamon, which is what I use).
Frankly I have given up hope on this ever working properly, I have spent way too many hours trying to fix this. It is sad because I am/was a huge fan of Sublime for many years (it being my main driver/IDE), but this issue renders it unusable with my workflow, which involves spreading out multiple projects across my workspaces.
FWIW, the script still works properly when opening sublime "projects" (although you have to open them via the sublime-workspace
file, as opening the sublime-project
file will occasionally cause sublime to crash - another long-standing issue on Linux).
If you want to look into tweaking the JSON file before launch, you can try https://github.com/trentm/json to do so, it works great. However, after having a quick glance at Session.sublime_session
, I could not figure out any workspace information that could be tweaked.
Best of luck!
Oh, sure, if I were to go the config-editing route, I'd probably use the python stdlib. But I'd still be deleting things that subl thought were important to save, which seems pretty wrong. Anyway, as I said, my workaround is good enough if you see subl as more of a one-off editor than a full IDE, which is how I use it.
You can add "remember_workspace": false
to your settings file
remember_workspace
makes Sublime Text remember what workspace each window was in last. When set to false the OS left to determine which workspace a window is opened in. This doesn't work with Wayland.
It worked for me.
@adip1343 Thanks, that seems to work on Windows, at least. I'll keep the workaround on Linux, and I guess check back in a few months (or maybe whenever I update my Ubuntu from 20.04) to see if remember_workspace
is honored there.
"remember_workspace": false
in Ubuntu 22.04 worked for me. Thanks, @adip1343
I can confirm that "remember_workspace": false also worked for me in Ubuntu 22.04
@odellcraig, thanks a lot!!!!
What a stupid behavior. This is annoying for every user working with multiple workspaces. Funnily i ditched GNOME-text-editor due to that and thought something more advanced like sublime would honor logical behaviour (no developer wants any file to open on a different workspace within a completely unrelated context). But wow, even here. Can not believe it.
sudo apt purge sublime-text