How do I close all open tabs at once?

104,036

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:

  1. :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.

  2. :conf qa :confirm qall

    Exit Vim. Bring up a prompt when some buffers have been changed. See :confirm.

  3. :qa! :qall!

    Exit Vim. Any changes to buffers are lost. Also see :cquit, it does the same but exits with a non-zero value.

  4. :quita :quitall :quita! :quitall!

    Same as :qall.

  5. :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.

  6. :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.

  7. :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
Share:
104,036
Srikanth
Author by

Srikanth

Updated on June 25, 2020

Comments

  • Srikanth
    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
    Dennis Kioko over 15 years
    Note, this isn't my answer. I moved this out of the original non-question down to here.
  • Bombe
    Bombe over 15 years
    “close all other tabs” is much faster achieved by “:on” (for “only”, i.e. “the only window to show”). :)
  • Boldewyn
    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
    MattK over 13 years
    :wqa can be simplified to just :xa
  • Justin Force
    Justin Force over 12 years
    :tabo is exactly what I was looking for. I'd upvote you 30 times if I could. :)
  • Aaron McMillin
    Aaron McMillin about 12 years
    Never 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
    Singlestone about 10 years
    @AaronMcMillin I use :x all the time, and have never accidentally encrypted a file.
  • Aaron McMillin
    Aaron McMillin about 10 years
    @Singlestone Good for you? I think the upvotes show that you maybe the exception.
  • Singlestone
    Singlestone about 10 years
    Good 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
    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
    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
    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
    studgeek almost 8 years
    Maybe remap X away from encrypt so it can never happen again (at least from one character :)?
  • Christopher
    Christopher over 7 years
    I noticed nobody said anything about using ZZ or ZQ which are the same as :x and :q!. If you're afraid of using :x because it's similar to :X then maybe give ZZ a go. That's my goto command for write and quit. Doesn't really answer the original question, but adds to this conversation.
  • wisbucky
    wisbucky over 4 years
    This 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
    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 of Shift (for : purpose) involves a pinky finger which is clearly pulled off the Shift while pressing x making it almost impossible to press Shift+x with respectively your pinky finger AND your ring finger unintentionally :) Anyway the advice is still worth obeying.
  • ᐅdevrimbaris
    ᐅdevrimbaris over 3 years
    You may close other people's sessions if you accidentally happen to be root. Not very funny :).