Live data from Hacker News

Tell HN: Vim users, `:x` is like `:wq` but writes only when changes are made

news.ycombinator.com

61–70 of 279 posts

Re: Tell HN: Vim users, `:x` is like `:wq` but writes only when changes are made

#61

I learned to do `:wq` after I learned that `:X` encrypts your file. When typing without really paying attention to the screen, I've twice encrypted my file with password like `cd tmp`, then saved the config file, breaking my system. After that, I switched to `:wq` (and sometimes `:w` `:q`) which is much safer against over-typing.

This command is no longer available in neovim, so it should be fine to use there.

Re: Tell HN: Vim users, `:x` is like `:wq` but writes only when changes are made

#62
post #45

I learned to do `:wq` after I learned that `:X` encrypts your file. When typing without really paying attention to the screen, I've twice encrypted my file with password like `cd tmp`, then saved the config file, breaking my system. After that, I switched to `:wq` (and sometimes `:w` `:q`) which is much safer against over-typing.

Thanks for this warning. Even worse for me, because my laptop keyboard has some kind of horrible encoding causing latency on the shift key, so I'm constantly doing :Wq when I type fast enough... Yeah I had the suspicion it was human error - but I've tested using a single finger for shift and w, so it's definitely the keyboard. [edit] Looks like that feature is not necessarily built in by default though.

i did an alias mapping :Wq to :wq

Re: Tell HN: Vim users, `:x` is like `:wq` but writes only when changes are made

#63

I learned to do `:wq` after I learned that `:X` encrypts your file. When typing without really paying attention to the screen, I've twice encrypted my file with password like `cd tmp`, then saved the config file, breaking my system. After that, I switched to `:wq` (and sometimes `:w` `:q`) which is much safer against over-typing.

I have computer-literate parents and grew up in the PC era, so as a child I typed my elementary school assignments in vi. Accidentally using :X, encrypting one of my school papers, and having to completely rewrite it, was one of the slightly-traumatizing moments in my childhood.

FWIW, I switched to :wq for a while but I'm back to using :x instead of :wq. I'm just very careful now. :)

Re: Tell HN: Vim users, `:x` is like `:wq` but writes only when changes are made

#64

I learned to do `:wq` after I learned that `:X` encrypts your file. When typing without really paying attention to the screen, I've twice encrypted my file with password like `cd tmp`, then saved the config file, breaking my system. After that, I switched to `:wq` (and sometimes `:w` `:q`) which is much safer against over-typing.

Thanks for bringing this up. I'm toying with either disabling it, cmap X or, mapping it down to a lower x. cmap X x 1. Does anyone see anything this could interfere with? 2. Does anyone know a better way to turn off the `:X` encryption option? Sadly, having to remap definitely dulls the shine of `:x`.

Well, in fairness, `:X` brings up a prompt, so an accidental `:X` won't seamlessly masquerade itself as `:x`.

Otherwise, I feel a remap is just a valid option as any to disable it. I'm not sure there's a way (a quick skim of the docs made me think `set key=` would do it but that didn't work for me, or at least I didn't understand what it does) but either way you'd still have to add config.

But again, as I say to everyone I see using commands to quit and keeps getting brought up here: `ZZ` is the same thing.

Re: Tell HN: Vim users, `:x` is like `:wq` but writes only when changes are made

#65

I learned to do `:wq` after I learned that `:X` encrypts your file. When typing without really paying attention to the screen, I've twice encrypted my file with password like `cd tmp`, then saved the config file, breaking my system. After that, I switched to `:wq` (and sometimes `:w` `:q`) which is much safer against over-typing.

In neovim, :X (and cryptography in general) is removed https://github.com/neovim/neovim/commit/85338fe

Re: Tell HN: Vim users, `:x` is like `:wq` but writes only when changes are made

#66

Earlier quoted context omitted.

I just tried this and I think that in 40ish years of typing on computer keyboards, this is the most difficult thing I've ever typed. And I use emacs.

What do you mean? Super easy and fluid, I've been doing it for about a decade. Left pinky on left shift, left middle finger (you could try ring I suppose) on zz, tap twice.

I mean pretty much what I wrote. It's literally the most difficult thing I've ever typed on a keyboard.

Blame my hand geometry or the keyboard or muscle memory or 10,000 other things, I just noted it was super hard and unnatural for me to type that. (The downvoting on that is pretty epic, though.)

Re: Tell HN: Vim users, `:x` is like `:wq` but writes only when changes are made

#67
post #6

Earlier quoted context omitted.

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

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"

Re: Tell HN: Vim users, `:x` is like `:wq` but writes only when changes are made

#68
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.

Re: Tell HN: Vim users, `:x` is like `:wq` but writes only when changes are made

#70
post #68

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.

Can't you use :q and then :x instead of :q then :wq ?
Post reply on HN