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

34,282

Solution 1

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

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

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

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

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".

Share:
34,282
firedev
Author by

firedev

Full-stack designer. Specializing in crafting components systems tailored to use cases on hand. Carefully stitching together back and front ends for improved user experience.

Updated on May 05, 2021

Comments

  • firedev
    firedev almost 3 years

    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.

  • firedev
    firedev over 11 years
    Unfortunately I can't set a shortcut on it: { "keys": ["super+shift+w"], "command": "close_all_files" } doesn't work. I probably could do it using keyboard prefPane, but since my Sublime config is synced through dropbox, I'd rather did it from within Sublime.
  • Alex
    Alex over 11 years
    Okay, 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. You'll have to restart Sublime first
  • slhck
    slhck over 10 years
    This is the default in Sublime Text 3 AFAICT.
  • geerlingguy
    geerlingguy about 10 years
    @slhck - It looks like that's a bug in build 3059. Sublime is supposed to close the project window when all the tabs in it are closed.
  • firedev
    firedev about 10 years
    In fact in Sublime Text 3 it is even worse. You close all tabs and then there is another shortcut to close the window. I always reach for the mouse, very annoying.
  • firedev
    firedev about 10 years
    The problem with Sublime 3 is that you can't close all tabs and then close the window with Cmd-W, you have to have a different shortcut for window closing.
  • firedev
    firedev about 10 years
    Sorry I don't think it works with Sublime 3. It closes all tabs yes, but the window stays open.
  • demisx
    demisx about 10 years
    I thought this was the original intent of the question. To be able to close all tabs, but keep the project window open. Maybe I've misunderstood something. Anyway, this shortcut is really helpful when you have a bazillions of tabs open and you just want them to close all at once. Use it all the time.
  • firedev
    firedev about 10 years
    Yes, but then sometimes you want to close window after that. And in Sublime 3 you got to reach for mouse or use another shortcut.
  • stef
    stef over 9 years
    sublime 3's latest build fixes this "bug", so it's the same behaviour as sublime 2 again. shame.
  • anthony_SelectiveFew
    anthony_SelectiveFew almost 9 years
    on linux debian I had to add: { "keys": ["ctrl+shift+w"], "command": "close_window" }
  • Gaston Sanchez
    Gaston Sanchez almost 9 years
    This worked for me on a mac with the latest build of sublime text 3 (build 3083).
  • o_O
    o_O over 8 years
    I don't see how you would not need a separate command? Is it supposed to read your mind to know if this time you want Cmd-W to just close all files and leave the window open or if this time you want to close all files and the window. That's impossible. You can bind Cmd-W to close all files and the window and then bind Cmd-? to close only files. That way you can get both.
  • gprasant
    gprasant over 8 years
    improved my sublime productivity today
  • Rockallite
    Rockallite about 8 years
    On OS X, this value is overridden in the platform specific settings, so you'll need to place this line in your user settings to override it.
  • getup8
    getup8 almost 3 years
    This is now File > Close All Files