422

If I have 10 tabs opened, I have to close each one using ":q" separately.

How can I close them all at once?

kenorb
  • 118,428
  • 63
  • 588
  • 624
Srikanth
  • 11,148
  • 20
  • 64
  • 87

8 Answers8

629

Shortest/simplest/fastest way would be:

:qa

To save work in all tabs and quit:

:wqa
fuentesjr
  • 45,682
  • 27
  • 72
  • 79
  • 34
    :wqa can be simplified to just :xa – MattK Jan 12 '11 at 20:42
  • 147
    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. – Aaron McMillin Apr 24 '12 at 20:41
  • 31
    @AaronMcMillin I use :x all the time, and have never accidentally encrypted a file. – Singlestone Feb 18 '14 at 15:02
  • 10
    @Singlestone Good for you? I think the upvotes show that you maybe the exception. – Aaron McMillin Feb 18 '14 at 16:02
  • 14
    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. :) – Singlestone Feb 18 '14 at 16:08
  • @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! – Brandon Mar 04 '15 at 23:52
  • 17
    @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... – jwd Oct 22 '15 at 15:56
  • @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 – Aaron McMillin Oct 22 '15 at 18:05
  • 5
    Maybe remap X away from encrypt so it can never happen again (at least from one character :)? – studgeek Jun 22 '16 at 01:53
  • 7
    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. – Christopher Nov 17 '16 at 22:49
  • @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. – bloody Mar 23 '20 at 12:54
214

I often use :tabo (:tabonly) to close all other tabs.

wisbucky
  • 22,510
  • 8
  • 103
  • 76
Christian C. Salvadó
  • 723,813
  • 173
  • 899
  • 828
  • 14
    “close all other tabs” is much faster achieved by “:on” (for “only”, i.e. “the only window to show”). :) – Bombe Feb 04 '09 at 08:01
  • 9
    @Bombe: for me it didn't work, too. `:on` only closes *windows*, not tabs, at least in my vim 7.3.3. – Boldewyn Sep 15 '10 at 09:35
  • 1
    `:tabo` is _exactly_ what I was looking for. I'd upvote you 30 times if I could. :) – Justin Force Jan 28 '12 at 19:32
  • 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. – wisbucky Nov 13 '19 at 00:30
27

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.

mmcdole
  • 86,293
  • 60
  • 181
  • 221
18

Adding to what fuentesjr said:

:qa!

Will force quit all tabs, if you don't care about saving.

Daniel Nadasi
  • 846
  • 5
  • 6
17

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
Christopher
  • 1,776
  • 15
  • 15
6
:qall

This closes all tabs and open buffers.

Vagmi Mudumbai
  • 617
  • 7
  • 14
0

here is an Dark Side way of closing ALL VIM INSTANCES on Linux/Mac

:!killall vim -9

Do not use it. It does what you ask but probably not the best way but fun way

0

I'm using the VIM plugin in VSCode and I was looking for a way to close all the tabs open on the current window.

The commands :qa and :wqa didn't work because they closed all the tabs from all the windows.

The command :tabonly closed all the tabs from the current window except the current tab.

Because I'm usually only using 2 windows at the same time, the closer I managed to get to my need was to focus on the other window and run the command :

:on

(:only) it closes all the windows except the current one.

Valentin Vignal
  • 1,128
  • 7
  • 21