Close all tabs, but not the window, in Sublime Text

Sublimetext2Sublimetext3Keyboard ShortcutsSublimetextShortcut

Sublimetext2 Problem Overview


Is there a way to close all tabs in one go in Sublime Text, but leave the window with the current project open? It is really annoying when I just want to close all open file and start the new task I have to Cmd-W them one by one. If I do Cmd-Opt-W it will close all tabs and the current project.

Sublimetext2 Solutions


Solution 1 - Sublimetext2

Thanks to Alex, it turned out kind of simple, Preferences > Key Bindings > User:

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

No need to restart Sublime, it works right away. And what's even better, no need to get used new shortcuts, you can still close Sublime window with Cmd-W after all tabs are gone.

Solution 2 - Sublimetext2

There's an option in the file menu, but it has no shortcut:

  • File -> Close All Files

Edit - change user settings:

kay, open Preferences -> Key Bindings - User and paste the following between the []:

{ "keys": ["ctrl+alt+shift+w"], "command": "close_all" }

then use Ctrl, Alt, Shift and w to close all tabs.

You'll have to restart Sublime first.

Note: For Sublime Text 3.2.2,Build 3211 you don't need to restart the sublime text to waste your time.Just place code in [ ](as mentioned above),save it and close Key Bindings - User window.Now all opened tabs will be close with out exiting Sublime Text by using Ctrl + Alt + Shift + W .

Solution 3 - Sublimetext2

Here is what I have set up on Mac Sublime Text 3

  1. Go to Sublime Text -> Preferences -> Key Bindings - User
  2. Add the following binding: [ ... ... ... { "keys": ["command+shift+w"], "command": "close_all" } ]
  3. Save file

Now, hitting "Command+Shift+W" will close all of your open tabs. Hitting "Command+W" closes current tab only. This is sort of consistent with Mac shortcuts for other app windows.

Solution 4 - Sublimetext2

By default, closing all tabs don't close the window, but beware: The last build 3059 (December 13, 2013) of Sublime Text 3 does now include:

> Automatically closing windows when the last tab is dragged out

It is managed by this setting:

// Set to true to close windows as soon as the last file is closed, unless
// there's a folder open within the window. This is always enabled on OS X,
// changing it here won't modify the behavior.
"close_windows_when_empty": false,

> I just want to close all open file and start the new task

In that same Sublime Text 3 build 3059, you also have the setting:

> When the last file is closed, a new transient file is created automatically

Combined with "File -> Close All Files", that can help starting quickly in a new file.

Solution 5 - Sublimetext2

Go to Preferences>Key Bindings - User> and add following line.

{ "keys": ["super+w"], "command": "close_file" }

Now when you hit cmd+w, only file gonna close not the whole window because you target "close_file".

Solution 6 - Sublimetext2

The Coolest way is : File - > Close All Tabs

Solution 7 - Sublimetext2

If you are like me, and actually prefer doing right click on a tab and select the Close All Tabs command, you can:

  1. Run the View Package File command in Sublime Text
  2. Select Default/Tab Context.sublime-menu
  3. Add the line:

> { "command": "close_all", "args": { "group": -1, "index": -1 }, "caption": "Close All Tabs" }

  1. Save. Restarting might be required.

Hints:

  • Tested in ST3, but the documentation I got this from was for ST2, so it should be fine
  • Do not forget to add a comma at the end of the line if it is not the last
  • For me it was not possible to edit the Tab Context.sublime-menu file because the folder it is supposed to be in was missing. It that is the case, just create it, for me it was $HOME\AppData\Roaming\Sublime Text 3\Packages\Default\
  • It is also possible to just create/edit the file directly instead of going through the package viewing process

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionfiredevView Question on Stackoverflow
Solution 1 - Sublimetext2firedevView Answer on Stackoverflow
Solution 2 - Sublimetext2AlexView Answer on Stackoverflow
Solution 3 - Sublimetext2demisxView Answer on Stackoverflow
Solution 4 - Sublimetext2VonCView Answer on Stackoverflow
Solution 5 - Sublimetext2Usman AhmedView Answer on Stackoverflow
Solution 6 - Sublimetext2Mohammad HeydariView Answer on Stackoverflow
Solution 7 - Sublimetext2TitolopolousView Answer on Stackoverflow