40

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.

MCK
  • 545
  • 2
  • 6
  • 10
  • 2
    Possible duplicate of [How to exit the Vim editor?](https://stackoverflow.com/questions/11828270/how-to-exit-the-vim-editor) – dlmeetei Aug 04 '17 at 13:42

3 Answers3

43

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)

Otto
  • 879
  • 9
  • 7
37

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

Robert Houghton
  • 1,202
  • 16
  • 28
9

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.

armanexplorer
  • 93
  • 2
  • 5
Rutvik Bhatt
  • 476
  • 3
  • 13