Live data from Hacker News

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

news.ycombinator.com

121–130 of 279 posts

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

#122
I have a question about this. If I type ":w" and then immediately do Ctrl+Z to suspend the session, it seems that Vim is always able to save the file before the editor suspends. Is this by design? Or was I just lucky so far?

Anyway, it would be great to have a default shortcut for this combination of keys too.

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

#123
post #76

Earlier quoted context omitted.

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.

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

Alias x to q, I think you mean?

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

#124

By the way, why does visudo sometimes give me another editor (like nano) on a new system. Isn't "vi" supposed to mean "vi"?

I think it uses whatever EDITOR is set to.

  EDITOR=vi visudo
should let you override it

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

#125
post #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

Thanks great link. tldr:

> vim encryption uses old, obsolete algorithms that are poorly implemented. Since insecure cryptography is worse than no cryptgraphy, the community voted in favor of removing all crypto.

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

#126
post #89

I'm rarely in a situation where I'd want to quit vim. One off config files on a remote machine perhaps?

Config files on an embedded device got me into using vim 10+ years ago. This seems to be a common use case. Eg, “I use vim for short term editing on remote machines but VS Code for any serious editing.”

This is not me though. I love me a plug-in heavy vim for coding sessions. Maybe one of these days I’ll be stuck working with some ECMA-based language and will finally start using VS Code.

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

#127
post #114

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, this is absolutely horrible. Filing this as yet another item under “Why vim is the worst example of 1970s bullshit UX still recommended by cargo cultists everywhere.”

Harsh but not unwarranted. What a bizarre keybind.

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

#128
post #3

I had a CS prof years ago tell us all the only thing we needed to know about vi(m) was the dammit key As in "escape-q-dammit"

Just throwing another one out there: `Ctrl + [` instead of `Esc` to save some finger travel.

ctrl+c is the same and even easier to type. I never use escape.

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

#129
post #112

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 just tried it. :X asks you to enter an encryption key, then asks you to enter it again, and only continues if the keys match. And then you're still in vim and need to save your file to overwrite anything. Seems hard to do by mistake. (though I prefer ZZ)

If only!

I was a TA for an introductory CS class that taught C++ and, in passing, vi. A hour before one assignment was due, a student showed up in a panic. “I just had it working but then the computer corrupted my file. Look! Can I have an extension?” The other TA and I smirked: What a lame excuse! We offered some generic advice about starting earlier and visiting office hours. He left in a huff.

A few minutes later, a second student appeared with the same story, and then a third and fourth.

We eventually tracked the problem down to some handwritten notes, where someone had written a largish :x for “save and quit.” The students were doing things like spamming :X (since it didn’t seem to respond the first time—-and it was over a sluggish ssh connection) or a reflexive quit-and-compile cycle. I think we eventually recovered one or two assignments by guessing what they might have done.

We obviously apologized profusely and the next class started with a discussion of :x versus :X—-and emacs!

Post reply on HN