Sunday, August 30, 2009

Firefox Tip: Prevent Ctrl-w From Closing The Browser

If you like using tabs when running Firefox, and you like using keyboard shortcuts, then you probably know that Ctrl-w closes the current tab. You probably have also have had the annoying experience of hitting Ctrl-w several times to close a sequence of tabs, and then pressed it one time too many, and closed Firefox itself.

It turns out you can prevent that from happening. Visit about:config, enter browser.tabs.closeWindowWithLastTab into the Filter: box, and when that setting appears in the main window, right-click it and choose Toggle, to set it to False. From then on, hitting Ctrl-W will close tabs in the familiar way, until you press it with only one tab open. In that case, you'll just get a blank tab, no matter how many times you press it.

One tiny annoyance: If you're like me and you don't like to have the tab bar visible when you've only got one tab open, you're out of luck once you've taken advantage of this feature. Still, this waaaay better than inadvertently closing the browser, and the good news is, next time you start Firefox, there won't be a tab bar when you only have one tab open -- this option doesn't get changed.

Thanks to Brad Linder for passing along this handy tip.

[Added] The real beauty of this, just in case you didn't already know, is that Ctrl-T (i.e., Ctrl-Shift-t) -- the keyboard shortcut for "undo close tab" -- can then be used to restore the tab you didn't mean to delete. Or, right-click on the tab bar, and choose that from the pop-up menu. And, as always, you can do this multiple times, to restore the 2nd, 3rd, ... most recently closed tabs.

Slowly, painfully, we're getting computers to do what we meant them to do, not what we told them to do!

9 comments:

Anonymous said...

I would like to turn off Ctrl+W completely. It is annoying as mistakenly pressing Ctrl+W closes the tab or window without warning.

bjkeefe said...

Do you know about Ctrl-Shift-T? (Or, equivalently, put your mouse cursor on another remaining tab, right click, and choose Undo Close Tab.

But yes, as a general principle, I wish Firefox supported redefining keyboard shortcuts.

bjkeefe said...

Sorry about the missing paren. And during this week of all weeks.

;)

Danno said...

Thank you so much, this is very useful.

bjkeefe said...

y/w. Thanks for letting me know you found it so.

Anonymous said...

Painfully endure for years. BIG thanks and kudo for bjkeefe. FF had done many time saving kudos for years, but this idiot mishap had taken it all away. Without a breath to disable force feed sour candy in everyones really tick me off.

bjkeefe said...

Thanks for letting me know, anon.

Anonymous said...

I was constantly doing this as I use CTRL+W in bash (basically, "delete word") all the time, to the point where I keep doing it while editing text in Firefox too.

After reading this thread on SuperUser, I tried the "Customizable Shortcuts" add-on by Tim Taubert, and re-mapped the shortcuts altogether.

andy said...

Just what I needed! Thanks SO much!

This usually happens to me when I have to write (blindly) something with a capital W. So it can happen I don't hit the left shift, but the key below -> KABOOM!

Fantastic, whenever you have written a longer e-mail and you can start over from the beginning.

ShareThis