When you’re down to the last tab on Safari and you hit Command+W to close that tab, Safari closes the window itself. This is one of Safari’s most annoying quirks. Thankfully, it does have a workaround that involves creating a simple keyboard shortcut.
When you have multiple tabs open in Safari, if you go to the File menu, you’ll see that the Command+W shortcut is assigned to the Close Tab function. So far so good.
Now close all unpinned tabs except one and visit the File menu again. What do you see? The Command+W shortcut appears assigned to the Close Window function. No wonder Safari closes the window when you use that shortcut.
To fix this behavior, first go to System Preferences > Keyboard > Shortcuts > App Shortcuts. Click on the + icon below the section on the right to create a new Safari shortcut.
In the dialog that pops up, choose Safari from the Application: dropdown, type Close Tab in the Menu Title: field, and hit Command+W when the cursor is in the Keyboard Shortcut: field. Save the shortcut by clicking on the Add button.
This tweak forces Command+W to trigger the Close Tab function every time you use it. The drawback here is that if you do want to close the last tab, you’ll have to close the window, either by clicking on the window’s Close button or by hitting Command+Shift+W.
Dear Apple: If I have 8 pinned tabs in Safari, closing the last non-pinned tab should not close the window. Love, Us.
— Craig Pearlman (@blackfog) February 25, 2016
You might also want to try the AppleScript shared in this Reddit thread to make Safari open a blank new tab when you close the last tab in that window. It did not work for me though.
If there’s a different fix that worked for you, tell us about it!
Image Credit: Vintage typewriter by MyImages – Micha via Shutterstock