How do I close all open tabs at once?
Solution 1
Shortest/simplest/fastest way would be:
:qa
To save work in all tabs and quit:
:wqa
Solution 2
I often use :tabo
(:tabonly
) to close all other tabs.
Solution 3
That can be done with the following command (in normal or escape mode):
:tabdo :q
"tabdo" apparently executes the command for all the open tabs.
Solution 4
Adding to what fuentesjr said:
:qa!
Will force quit all tabs, if you don't care about saving.
Solution 5
You can use any of these Vim Ex commands to Exit Multiple Windows And Buffers:
:qa
:qall
Exit Vim, unless there are some buffers which have been changed. (Use
:bmod
to go to the next modified buffer). When 'autowriteall' is set all changed buffers will be written, like:wqall
.:conf qa
:confirm qall
Exit Vim. Bring up a prompt when some buffers have been changed. See
:confirm
.:qa!
:qall!
Exit Vim. Any changes to buffers are lost. Also see
:cquit
, it does the same but exits with a non-zero value.:quita
:quitall
:quita!
:quitall!
Same as
:qall
.:wqa
:wqall
:xa
:xall
Write all changed buffers and exit Vim. If there are buffers without a file name, which are readonly or which cannot be written for another reason, Vim will not quit.
:conf wqa
:confirm wqall
:conf xa
:confirm xall
Write all changed buffers and exit Vim. Bring up a prompt when some buffers are readonly or cannot be written for another reason. See
:confirm
.:wqa!
:xa!
:wqall!
:xall!
Write all changed buffers, even the ones that are readonly, and exit Vim. If there are buffers without a file name or which cannot be written for another reason, Vim will not quit.
To read about these in Vim, type the following Ex command
:help window-exit
Srikanth
Updated on June 25, 2020Comments
-
Srikanth almost 4 years
If I have 10 tabs opened, I have to close each one using ":q" separately.
How can I close them all at once?
-
Dennis Kioko over 15 yearsNote, this isn't my answer. I moved this out of the original non-question down to here.
-
Bombe over 15 years“close all other tabs” is much faster achieved by “:on” (for “only”, i.e. “the only window to show”). :)
-
Boldewyn over 13 years@Bombe: for me it didn't work, too.
:on
only closes windows, not tabs, at least in my vim 7.3.3. -
MattK over 13 years:wqa can be simplified to just :xa
-
Justin Force over 12 years
:tabo
is exactly what I was looking for. I'd upvote you 30 times if I could. :) -
Aaron McMillin about 12 yearsNever use
:x
never never never. You'll screw up some day and do:X
encrypt your file, and you won't know the key. -
Singlestone about 10 years@AaronMcMillin I use :x all the time, and have never accidentally encrypted a file.
-
Aaron McMillin about 10 years@Singlestone Good for you? I think the upvotes show that you maybe the exception.
-
Singlestone about 10 yearsGood for me indeed! I may be the exception. I am at least a data point. Never say "never never never", that's my motto. :)
-
Brandon about 9 years@dhblah :q! is most definitely not the same as :qa! Open two buffers, make unsaved changes in both, then try using :q! You will be sent back and forth between them until you finally use :qa!
-
jwd over 8 years@AaronMcMillin: I know this is an old question, but at least on my current Vim, you would have to (1) type uppercase
X
(2) accidentally enter a password, (3) accidentally enter the same password again, before this would be a problem. I don't see that as very likely... -
Aaron McMillin over 8 years@jwd That's good to know. I've been vim'ing for a long time. and I know I have encrypted files and not been able to open them because of not following was happened after :X
-
studgeek almost 8 yearsMaybe remap X away from encrypt so it can never happen again (at least from one character :)?
-
Christopher over 7 yearsI noticed nobody said anything about using
ZZ
orZQ
which are the same as:x
and:q!
. If you're afraid of using:x
because it's similar to:X
then maybe giveZZ
a go. That's my goto command for write and quit. Doesn't really answer the original question, but adds to this conversation. -
wisbucky over 4 yearsThis has a side benefit that it still keeps all the tabs in the buffer list. You can see them with
:ls
. So you can still recover the tabs later if you want. Or convert them to windows, etc. -
bloody about 4 years@Aaron Whereas your advice is of the highest value, if someone blind-types then
x
is pressed always with a ring finger and natural holding ofShift
(for:
purpose) involves a pinky finger which is clearly pulled off theShift
while pressingx
making it almost impossible to pressShift+x
with respectively your pinky finger AND your ring finger unintentionally :) Anyway the advice is still worth obeying. -
ᐅdevrimbaris over 3 yearsYou may close other people's sessions if you accidentally happen to be root. Not very funny :).