What is the difference between :q and :qa! in Vim?
Solution 1
The key difference is the exclamation mark here. :q
will warn you about unsaved changes and will not let you exit. :q!
will not warn you.
See also :help quit
(type that in vim)
Solution 2
I don't see any of the answers specifically addressing the meaning of 'a' so thought I'd contribute:
:q
is quit, as you know, but warns you didn't save
:qa
is quit, all buffers, without saving but you'll get that same warning
:qa!
is quit all buffers, without saving, and without a warning
Solution 3
When you have some changes and use :q
, it fails and throws an error stating No write since last change
. In order to quit from the Vim without saving changes, you should write :q!
, it will quit the Vim and !
will work as a negation, which will negate the write operation.
When you fire :qa!
, it quits the vim and doesn't throw an error mentioned above as you have added !
. And there is no argument like a
if you see man vi
. (Just to note, arguments are case sensitive and -a and -A are treated differently)
In order to save the file and then quit the vim, you should use :wq
, as it will first save the file and then quit the Vim.
MCK
Updated on August 21, 2020Comments
-
MCK over 3 years
I'm quite new to Vim so I first checked the help.txt file to inform myself about Vim. Here I saw the following:
Close this window: Use ":q".
Get out of Vim: Use ":qa!" (careful, all changes are lost!).The first one closes Vim. The second one also. Wouldn't all changes also go with :q? To be clear, I use the vim GUI not a command prompt.
edit: It's more about the difference, not the actual meaning. The almost same explanation in the help.txt file confused me.