Sublime Forum

Missing: Shortcut to TOGGLE between two windows


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




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

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

then this to User/

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


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



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 ?



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 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:

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


  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



check this:

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



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()

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



I was able to copy the code (with bug workaround for OSX) from 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…




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 (with code from linked gist) into ~/Library/Application Support/Sublime Text 3/Packages/User



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.