At the end a light topic. How can we quit vim?

The well knows way is :wq. Which will save the file (w) and quit (q). What if we don’t want to save just quit? We can use :q, but it will cry if we have unsaved changes, we can shout at vim with :q! to quit and ignore errors.

It’s fine, but we have :x which is :wq, but it saves only if we have changes. It is good because we don’t want to write if we have nothing to add, unnecessary file system operation.

Can we do it better? Yes we can. We can simply use ZZ in normal mode. It’s the same as :x, but we don’t have to enter command mode. What if we don’t want to save only quit? Do we still have to use :q!? No, vim got our back and we have ZQ which is the same as :q!.

What if we have more than one file open, in multiple windows? We can use :qa as quit all. We can combine it with save as :wqa and we can force it without save :qa!.


I hope you enjoyed the whole Advent of Vim series and you learned a few things about vim.