Lurker News
`:x` leaves the modification time of files untouched if nothing was changed.

    :help :x
        Like ":wq", but write only when changes have been made.

Comments (270) 59 threads

Earlier comments
Block77#
ZZ gang
secondcoming8 replies#
Why would it write if no changes have been made?
wruza#
Because it commands to “write”. Also related to 'autoread'.
aendruk#
Because you told it to write.
Sakos#
I can imagine any number of situations where it might be wanted. Keep the file open in vim, changes are made from somewhere else, but you'd like to keep the original version, so you :w. It makes sense to me the :write actually writes regardless of context (assuming sufficient permissions) and with no hidden conditions like "something must have changed". That kind of thing leads to weird user behavior like editing whitespace just to be able to re-save a file.
Eleison23#
There are strange cases which may make this a logical choice. Since vi doesn't traditionally lock the file it's editing, another process could change the file on-disk while you have it in the editing buffer. I think you'll get a message in these situations, because it's usually not what you want. Then you'd have the choice of writing out the buffer, whether it's changed or not, to restore the contents of the file from when you began your vi session.
ergonaught#
If you tell it to write, and it doesn't write, then it is no longer your tool, but rather someone else's tool that you happen to be using.
dwater1 reply#
Vim is from an era when software was written to do exactly what you commanded it, not what you intended. It was your responsibility as a user to learn how to turn your intentions into commands.
zzo38computer#
Unfortuantely, too many modern programs are not designed to do what you commanded it and try to believe they know better than you do (which is often wrong, anyways). (The other problem is often not designed that expert users can use and can be programmed and used with other programs (e.g. using pipes).) I think that vi is better, in this way; it does do what you commanded it, and can be programmed and used with pipes, so it is better.

Nevertheless there are such thing as adding a confirmation message in case of a dangerous operation (and, if necessary, and option to disable such warnings). For example, C compilers usually have warnings, and you can disable any warnings that you do not want.

jstanley#
Why would you ask it to write if you don't want it to write?
vidyesh#
Its one of the things about exiting Vim. If you type :q, and there are unsaved changes it will prompt you to save it first and not let you quit.

So most people do :wq so that it saves and then quit or do :q! to quit without saving changes. Most people stop using :q.

All comments shown.