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

Show all comments

Showing thread 2 of 59

sshine6 replies#
I always :q when I didn’t change anything.

If I changed something intentionally, :wq and :x are equivalent. If I changed something accidentally, :x won’t catch that, and :q complaining will require me to decide if :q! or :wq is correct.
So :x does not fit my workflow of avoiding accidental writes. Just like ZZ does not.

hhjj1 reply#
Can't you use :q and then :x instead of :q then :wq ?
sshine1 reply#
Yes, but if I :q and it complains that the file was modified, and I decide that the change is worthwhile, :wq and :x are equivalent, since :x is only different when the file isn’t modified.

You may argue that :x is shorter, but one thing is character count and another is muscle memory distance because of mnemonic similarity between :q and :wq.

caust1c1 reply#
Could alias x to wq? :-) That's what I'm doing after discovering this!

Continue this thread — 1 reply

pkulak1 reply#
I use :x cus it's one less keystroke. And yes, I still use :q to make sure I don't save in case I changed something by mistake.
JelteF1 reply#
ZZ is only 3 keystrokes as opposed to 4 for :x (shift + z + z = 3 and shift + ; + x + enter = 4). It also doesn't require timing the release of shift before the press of x.
pkulak2 replies#
Wow! Never knew that existed. If I can undo 20 years of muscle memory, I'll use it. :D

EDIT: Just tried it, and Z being right next to Shift is a deal breaker.

Continue this thread — 2 replies

renewiltord#
It's funny but I use q when I don't intend to change things and wq in whatever state I'm seeing them and x when I'm working on clean git state.

Honestly it sounds complex, but I don't even think about it and it only struck me reading your comment.
The warning note on q is desirable.

julesnp#
I use the 'confirm' option in my vim config, that way I can always use :q and then get a prompt on what to do if a file's been changed.

I also map to :q to speed things up a bit.

silisili#
This is precisely why I use w and q instead of x. Not knowing if it wrote is definitely not a feature I'd want.
bigmadwolf#
ZQ will quit without writing anything.