As akshay pointed out, Vim's documentation explains, that
ZZ are equivalent and only save a file if the associated buffer has been changed.
:wq saves the buffer to the corresponding file, even if it is unchanged.
In both cases, the contents of the buffer will be saved to disk. Obviously the outcome is the same, so why bother, right? But wait... There is a subtle, but not irrelevant difference.
If you exit Vim via
:x and there has been no change to the buffer, there will be no change to the modification time of that file. On the other hand, if you quit via
:wq, the modification time will change, as the file is technically rewritten (saved again).
This can have some impact in certain situations. For example a backup process that is dependent on modification time, could store this file (and potentially send it over the network) even if no additional information has been included. Or some monitoring process could ring an alarm if it detects that (for it) the file has been changed...
Edit: I forgot to mention, in order to leave an modified buffer/file without changing the modification time, a
:q (without the
w) will work, too.
ZQ) is shorter and easier to type ...
:help :x. It's right there in the docs.