Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Keybinds (in normal mode):

Shift + ZZ -> :x (save only if needed and quit)

Shift + ZQ -> :q! (quit without saving)



I always use ZZ! It’s so much more convenient to type with one hand


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.


Irreversible? There's undo and version control.


Yes, and file system snapshots and remote sync. But writing to a file, in the general case, is an irreversible action.


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.


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.


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.


You need to make an effort to understand that RTFM is not the answer to the reproval of improper design, and shifting the goalpost from "discoverable user interface" to "looking for documentation and learning materials" does not do any favours to your argument.

A possible correct solution is already given as an example in my previous post.


I wasn’t shifting goalposts, only noted that the state of tutorials doesn’t explain much in the light of the described phenomenon. Apologies for this venture.

Granted, it would be nice to see more apps using the solution you described. But personally I don’t find a list of commands in a table that much different from a list of commands in a text wrt discoverability.

Another nuance discussed here https://news.ycombinator.com/item?id=34287407#34293277


If you’re learning Vim, command mode instructions are a LOT better because they actually show up on the screen.


> Shift + ZZ

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


I always thought of it as an "easy enough to type but hard enough to never cause an accidental quit" mapping.


Why, it's super obvious. Put vim to sleep.


It's a vi keybind, so the keymap wasn't even that exhausted yet!


Vim has way worse in its defaults. gqq, naturally, formats the current line.


I use `gq<movement (mostly paragraph)>` a lot. It’s a bit of a mouthful :p


Also g?? for… encoding the current line in ROT13.


It’s been like that since vi


huh. I'm using ZZ all the time, but I thought it is :wq


It's possible it was at some point, but my local copy of vim tells me it is 'same as ":x"' in `:help ZZ`


You never accidentally used it on an unnamed buffer?


unnamed as [No Name]? both :wq and ZZ (:x) do the same: "E32: No file name"


Sorry, unnamed AND unmodified. My bad.

And actual advantage here is that `ZZ` can be your "quietly quit anything" key. It'll close quickfix, locationlist, previewwindow, etc without complaining.


I like to add:

Shift + ZA -> :up (save only if needed without quitting.)

by adding to your .vimrc:

    nnoremap ZA :update<CR>




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: