Kurt Keller's Blog

tech notes and more

save and quit

You all know how to save and quit a file in vim. I see most people using :wq! every time. I’m not quite happy with this. This command will save the file even if it has not been changed, and thus change the timestamp on the file, and it will also try to write to read-only files. I usually use the command ZZ, which is not only easier to type, but also saves the file only if there have been changes to it. When there were no changes to the file, this command simply quit the editor. ZZ is the same as :x. With the latter, you can also say this should be done for all open files: :xa.

:wq write current file and quit
:wq! write current file even if read-only and quit
:x ZZ write current file if changed and quit
:wqa :xa write all changed files and quit
:wqa! :xa! write all changed files even if read-only and quit
:q quit current file if unchanged
:q! ZQ quit current file, ignoring any changes
:qa quit all files if unchanged
:qa! quit all files, ignoring changes
Share

Leave a Reply