Sublime Forum

Missing: Shortcut to TOGGLE between two windows

#1

I’m coping with this for a long time and once in a while I go spend half an hour googling about how to do this, but no success.

I decided to write a question here as last hope :slightly_smiling:

For example if I have 7 windows open, then CMD+` just cycles through them…

I want the usual toggle functionality like the system switcher (CMD+TAB) - there I don’t have to cycle through all open applications to get back to the previous one.

So how could I achieve this simple thing in Sublime? thank you

0 Likes

#2

:slightly_smiling:

You can add this to User/Default.sublime-keymap

{
	"keys": ["f8"],
	"command": "toggle_windows"
},

then this to User/toggle_windows.py
https://dl.dropboxusercontent.com/u/9303546/SublimeText/commands/toggle_windows.py

It will toggle between the last two, but you can customize it to cycle all. Is not system wide, is just a ST command.

1 Like

#3

Doesn’t CMD + shift + ` cycles back to the previous window?

0 Likes

#4

no, it cycles back to the previous window in the list, not where I actually was

tito: thank you, I tried it, but so far it’s not working, F8 just shows the title bar, so something does happen, but I’m not sure, it’s actually calling your script… how can I debug this… is there something I can add to the script, like a popup so I can see ?

0 Likes

#6

I learned how to debug plugins a little bit… so I saw in the console that your plugin is loaded, then I changed its ToggleCommand to put something to the buffer (like in hello world example)… I then tested that F8 indeed triggers the command and it does… then I restored the original code of toggle_windows.py and again when I press F8 the current window is highlighted… Here I stop debugging for now because it seems this plugin is broken… Can someone confirm it works for you? If not, I can investigate how to fix it, but a bit later.

In the meantime I found additional cool trick:

https://packagecontrol.io/packages/GotoWindow

Press command+shift+o and the list of all open windows pops up - very nice…!

but I would still like to toggle between two windows with one shortcut…

thank you
david

0 Likes

#7
  1. change the shortcut to “a” instead of f8
  2. close sublime text
  3. reopen sublime text
  4. open a new window
  5. open another new window
  6. press “a” repetitively, it should toggle windows.

if you didnt focus at least two windows, it will not work
maybe f8 does something system wide.
at least it works on windows and I think it should work in osx

0 Likes

#8

check this: http://cl.ly/1A2i1u1l0O2E

I changed it to ‘a’ and this wasn’t a problem, the current window still focuses but it doesn’t switch to the other window… am I still doing something wrong?

thank you

0 Likes

#9

I debugged and everything seems to work except the last part - actually focusing the window:

def workaround_bug_on_focus_view(self, view):
    window = view.window()
    window.focus_view(view)
    window.run_command('focus_neighboring_group')
    window.focus_view(view)

this code dosn’t manage to focus the window on mac.

0 Likes

#10

I was able to copy the code (with bug workaround for OSX) from https://github.com/ccampbell/sublime-goto-window/blob/master/GotoWindow.py as the user Randy3k suggested here: Focusing the window, so the working script for toggling windows on OSX is here:

I’m still bothered by a small delay while switching because of how workaround has to be done…

0 Likes

#11

Update:

Looks like the hack is not needed anymore on macOS Monterey & ST 4126 and so delay goes away…

I updated the code in gist, this script now works perfectly for switching recently open windows:

Edit Preferences / Key Bindings for User and add this:

{
  "keys": ["f3"],
  "command": "toggle_windows"
},

then put toggle_windows.py (with code from linked gist) into ~/Library/Application Support/Sublime Text 3/Packages/User

0 Likes

#12

on a mac, f3 still switched to mac spaces/mission control.

I had to use a different key

{
  "keys": ["super+shift+["],
  "command": "toggle_windows"
}

for it to work.

0 Likes