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
cmeacham985 replies#
Keybinds (in normal mode):

Shift + ZZ -> :x (save only if needed and quit)
Shift + ZQ -> :q! (quit without saving)

codesnik2 replies#
huh. I'm using ZZ all the time, but I thought it is :wq
cmeacham98#
It's possible it was at some point, but my local copy of vim tells me it is 'same as ":x"' in `:help ZZ`
sodapopcan1 reply#
You never accidentally used it on an unnamed buffer?
codesnik1 reply#
unnamed as [No Name]? both :wq and ZZ (:x) do the same: "E32: No file name"

Continue this thread — 1 reply

hitpointdrew2 replies#
I always preferred these over the :wq! And :q!, but for some reason seem way less popular. Most tutorials don’t even mention ZZ and ZQ.
KMnO4#
If you’re learning Vim, command mode instructions are a LOT better because they actually show up on the screen.
bmn__1 reply#
A good software interface must be discoverable by the user. I imply here that hardly anyone knows about ZZ because of improper design, which explains why it's not generally mentioned in tutorials.

Compare vim or its clones with any KDE application, which always has keybindings shown in menus, and always a complete list of rebindable keybindings in the settings menu.

wruza2 replies#
Your implication looks strange considering that ZZ is literally the first command mentioned in “The first steps in Vim / Getting out” section. Most likely it isn’t mentioned in tutorials because these are 99% copypaste medium bullshit from wannabe teachers.

https://vimdoc.sourceforge.net/htmldoc/usr_02.html#02.7
To exit, use the "ZZ" command. This command writes the file and exits.
I remember reading about it 17 years ago in this manual. Tbf, it could have been in another section back then, but that is no excuse for seeking some “easy” tutorials instead of R-ing the TFM. There must be a name for this syndrome when people look for documentation and learning materials in anywhere but the documentation and the learning materials.

Continue this thread — 2 replies

0x45696e6172#
I like to add:

Shift + ZA -> :up (save only if needed without quitting.)
by adding to your .vimrc:

    nnoremap ZA :update
avgcorrection5 replies#
> Shift + ZZ

That’s a real “geez, our keymap is almost exhausted!” keybind.

amalgamated_inc#
Why, it's super obvious. Put vim to sleep.
sodapopcan#
I always thought of it as an "easy enough to type but hard enough to never cause an accidental quit" mapping.
asplake#
It’s been like that since vi
CGamesPlay2 replies#
Vim has way worse in its defaults. gqq, naturally, formats the current line.
avgcorrection#
I use `gq` a lot. It’s a bit of a mouthful :p
xigoi#
Also g?? for… encoding the current line in ROT13.
naniwaduni#
It's a vi keybind, so the keymap wasn't even that exhausted yet!
thiht1 reply#
I always use ZZ! It’s so much more convenient to type with one hand
sshine1 reply#
I really like having to use both my hands to perform an irreversible change to disk. Those extra milliseconds let me think through what I’m doing.
xigoi1 reply#
Irreversible? There's undo and version control.

Continue this thread — 1 reply

chrismorgan#
The really fun part:

> This command is not supported in Vim9 script, because it is too easily confused with a variable name.
So you can’t just write “x”, but must instead go for something bland like “exit”, or something exciting like “exe'x'”. (I’m presuming “execute 'x'” will work, but my mental model of how you’d unsupport the command in Vim9 script could be wrong.)

williamsmj3 replies#
`:cq` exits vim with exit code 1.

This is useful if you're in vim to write a git commit message and you realize don't actually want to commit. Or you're in vim from `fc` to edit a shell command and you realise you don't actually want to run it.

wruza#
VCSs usually abort a commit if a temporary message file remains unmodified, so :q! is fine too.
drudru#
Agreed. I use this all the time.
turtleyacht#
Thank-you. That beats `HdG :wq` to delete everything and abort the commit.
johncoltrane5 replies#
Front page and more than a hundred comments for a basic Vim command. Reddit is leaking.
NegativeLatency#
I may not be an uber geek but I’ve been using vim for 10 years, even written a plug-in and I didn’t know this.
pungentcomment#
You get that kind of response anytime the subject matter is vi or vim. Still more if it mentions nvim, nano or, god forbid, emacs(!)
badrequest#
Sorry we're not all living up to your expectations.
Arisaka11 reply#
What do you mean by "Reddit is leaking"? Do we hold ourselves to a higher standards out of merit of posting here? Is there some sort of tribalistic exclusivity that was broken? Was there perhaps a manual of commands a Vim user who posts here must know before creating an account?
_blz2#
The chances of the crowd here using emacs or vim are very high. Yes that makes it an 'elite board' if you consider basic editor commands as the standard.
flippinburgers#
Hasn't it been obvious for years now that the demographic on HN has shifted?

Load more comments