Hacker News new | ask | show | jobs
by always_good 3042 days ago
:x is a shortcut for :wq. I wonder why nobody knows it.
2 comments

:x is not only a short for :wq - the latter saves (unconditionally, even if you have saved earlier and not edited since), and then quits (the file). I was going to say that :x is also a shortcut for :q (just quit) but it is of course not a shortcut for that, since it is the same length :)

I can better describe it like this:

:x is a shortcut for telling vi/vim: save the file if not saved after last change, then quit (in either case, whether a save was needed and done just now or not) - IIRC.

Also, as others said, Shift-ZZ (when Caps Lock is off), also saves and quits (and saves one keystroke over :x - because you have to hit Enter after :x, but not after Shift-ZZ :) It is also (slightly) faster to type, since the (left) Shift key is just next to the Z key (at least on some keyboards, like mine at present).

I've never used :wq, always :x. And I've been using vim for roughly 3 years.
Sorry, I’m pretty new to vim (switched from ST this week and loving it so far). Thanks for the advice though