What is the difference between :q and :qa! in Vim?
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.
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)
The order of the command you fire is important.
When you use :q, it will not allow and will throw an error stating No write since last change
. In order to quit from the Vim with out 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 will first quit the vim and won'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, argument are case sensitive and -a and -A both are treated differently)
In order to save the file and then quit the vim, you should use :wq
, as it will fist save the file and then quit the Vim.
上一篇: 亚马逊EC2。 问题与权限
下一篇: 有什么区别:q和:qa! 在Vim中?