What is the Vim command to quit all open windows? - vim

:q only closes the current window. If you are using tabs or split windows, you need to do :q for all of them. Also, plugins like NERDTree and MiniBufExpl have their own windows, which need to be closed individually.
Is there a command to quit all these open windows and quit Vim in a single stroke? However, if there is some buffer or window with unsaved changes, I should be asked to save it or not. Any command to achieve this?
I hope this is not a strange request, because this is how most non-Vim editors with tab or splits work.

You can quit all loaded and open buffers, splits and tabs with:
:qa
If you want to quit without saving:
:qa!
You could assign a mapping to do this with a single stroke, this assigns the comma to quit everything without prompting to save:
nnoremap , :qa!<CR>
:wqall writes before closing, that might be useful.
Type :he :qa in vim for more info

you can user the
:qall
:qa
quit all the tabs opened
then you can use the command
:tabo
quit all other's tabs
if your's vim is not tabs you can use
:on
quit all windows

Related

How to auto-close vim's initial buffer on file open?

So I'm using ctrlp and nerdtree. I found it troublesome whenever I enter vim, open a file by ctrlp or nerdtree, my cursor always jump to a newly opened window while the initial empty buffer window is still opened, occupying the screen. Then I always have to do <C-w>j <C-w>q -- while I've trained myself to do it with my mechanical memory, I guess there should be some smart ways to auto-close the empty window once any file is firstly opened.
Appreciate all help/tip provided in advance. This is my current .vimrc.
Update:
Thanks #romainl and for NERDTree I've no issue now. I'm checking how to configure ctrlp though.
Pressing enter will open the file in the same window, as #romainl said.
However, another tip: If you want to see only the current window, you can run
:only
which will hide all but the current split (buffers will be hidden)
I have remapped it to <leader>o
" maximize current visible window
nnoremap <Leader>o :only<cr>

Vim map :q to quit without saving

I would like Vim to quit without saving when I enter :q.
It annoys me when Vim prompts me to save when I try to quit a document with :q having made changes to it. Whenever I want to keep changes I save them. Plus the ! of :q! is awkwardly positioned on my UK keyboard. How can I remap :q to act like :q!?
You can use cabbrev, that works like a map from a command line instruction to another one, like:
:cabbrev q q!
So now just type:
:q
and it will omit changes to exit without asking.

How to check in Vim why my buffers stopped working? Or how to reload Vim?

Sometime when I open file and open buffer list :ls my buffer list is empty even when I had some open files before.
Then I have to quit vim and open again to get buffers works.
Is the way to restart/reload vim without closing window?
For now I know that it usually happens when I close buffer by :bd or :BD(bfkill) or maybe it can be related with closing open split window.
This is my vimrc: https://gist.github.com/1791434
My guess is you might have bufhidden set to unload, delete or wipeout
Check that with
:verbose set bufhidden

I should get a command prompt rather than a popup when I try to close an unsaved window

I am using git configuration mentioned here
If I create a new tab and then if I do commmand W ( I am using mac) to discard that window then I get a popup for which I have to use mouse.
I have seen others use vim where in similar cases they get a prompt at the bottom which is something like
C for cacel
N for No.
S far Save(not sure).
What configuration change I need to do so that I start getting command prompt rather then GUI prompt?
I am using macvim.
What you're looking for is:
:set guioptions+=c
command W is a standard the MacOS close tab key stroke. You can use vim's own :q or :q! to close it and forget any changes to the buffer.
If you're using macvim (currently my favorite incarnation of Vim for the Mac), the prompt you get, while GUI-ish like the rest of Macvim, is keyboard-controllable: return to accept the default Save, Esc to Cancel, command-D to mean Don't Save (i.e. quit and lose changes). If you're using Apple=supplied vim on Apple's Terminal.app, the popdown from command W (which doesn't offer Save but just Cancel and Close) is similarly keyboard controllable: Esc to Cancel, return to accept the default Close (and lose unsaved changes, if any).
If you're using some other version of vim, it would help if you let us know which one!-)

How do I close all open tabs at once?

If I have 10 tabs opened, I have to close each one using ":q" separately.
How can I close them all at once?
Shortest/simplest/fastest way would be:
:qa
To save work in all tabs and quit:
:wqa
I often use :tabo (:tabonly) to close all other tabs.
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.
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
Adding to what fuentesjr said:
:qa!
Will force quit all tabs, if you don't care about saving.
:qall
This closes all tabs and open buffers.
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
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.

Resources