Skip to content

Instantly share code, notes, and snippets.

@MattDMo
Created November 4, 2020 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MattDMo/3bb35ec5f91ef2d06ada62f78fe00ef4 to your computer and use it in GitHub Desktop.
Save MattDMo/3bb35ec5f91ef2d06ada62f78fe00ef4 to your computer and use it in GitHub Desktop.
Sublime Text - Close all open windows
import sublime
import sublime_plugin
class CloseAllWindowsCommand(sublime_plugin.ApplicationCommand):
def run(self):
for win in sublime.windows():
win.run_command("close_window")
[
{ "keys": ["ctrl+alt+shift+w"], "command": "close_all_windows" },
]
@MattDMo
Copy link
Author

MattDMo commented Nov 4, 2020

This is in response to this StackOverflow question which asks how to close all open windows at once.

First, select Tools → Developer → New Plugin… and change its contents to that of close_all_windows.py above. Hit Save and it will automagically save it to your Packages/User folder, where Packages is the folder opened when selecting Preferences → Browse Packages…:

  • Linux: ~/.config/sublime-text-3/Packages
  • OS X: ~/Library/Application Support/Sublime Text 3/Packages
  • Windows Regular Install: C:\Users\YourUserName\AppData\Roaming\Sublime Text 3\Packages
  • Windows Portable Install: InstallationFolder\Sublime Text 3\Data\Packages

Next, select Preferences → Key Bindings and add the keybinding in Default.sublime-keymap to the User keybindings on the right. I chose CtrlAltShiftW, feel free to customize it if you want. Make sure you save the file when you're done.

Now, when you're in a situation where you have a ton of open windows you want to get rid of, just hit the keybind and they'll all close, unless there are unsaved files open, in which case it'll ask if you want to save or cancel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment