News for hackers. Stuff that matters.
Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by waisbrot on Saturday January 07, 2023 @09:49AM (#34288446)
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.

Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by tomxor on Saturday January 07, 2023 @10:01AM (#34288562)
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.

Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by DwnVoteHoneyPot on Saturday January 07, 2023 @10:46AM (#34289077)
i did an alias mapping :Wq to :wq
Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by dunham on Saturday January 07, 2023 @11:36AM (#34289666)
Yeah I do that a lot. And on macos, vi decides that :Wq is an error and returns a non-zero status code on my subsequent :wq, cancelling my git commit. So I get to type the commit message again.
Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by manaskarekar on Saturday January 07, 2023 @10:18AM (#34288751)
Thanks for bringing this up.

I'm toying with either disabling it,

    cmap X <Nop>
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`.

Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by sodapopcan on Saturday January 07, 2023 @10:47AM (#34289090)
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 wh... by manaskarekar on Saturday January 07, 2023 @11:00AM (#34289270)
Yeah, but it's possible to quickly type the next command (that you would after exiting vim) as the encryption key.

That said, given that neovim doesn't have this feature at all makes it less of an issue to me.

Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by bravetraveler on Saturday January 07, 2023 @12:29PM (#34290338)
On my build, I have to confirm the key -- is this not the case with yours?

I suppose one could naively type the same thing twice, but I feel like some caution also goes a long way. Driving without looking at the road is generally dangerous

Any time I accidentally shift-mod my saves, I immediately see the encryption prompt, and back out with SIGINT. I don't really buy the problem, so to speak

Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by withinboredom on Saturday January 07, 2023 @03:27PM (#34292375)
On a laggy/slow ssh connection, if you don't notice the encryption prompt, it is quite easy to just try the exact same thing again.
Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by bravetraveler on Sunday January 08, 2023 @12:17PM (#34300950)
Indeed - hence the tendency towards caution over what I type

I understand how it manifests... but I find it not that difficult to avoid

My answer to lacking feedback isn't moving forward headstrong - it's verify the delicate combination went through fine

Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by withinboredom on Sunday January 08, 2023 @02:44PM (#34302362)
Everyone has different responses when things don’t work out exactly how we think they will. Ideally, we write software that doesn’t surprise us, however we choose to react.
Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by bravetraveler on Sunday January 08, 2023 @07:33PM (#34305145)
The endless battle continues, be brave
Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by queuebert on Saturday January 07, 2023 @11:05AM (#34289323)
Mapping to 'x' is dangerous since on a system where you don't have your vimrc you'll get the original behavior of 'X'. Ideally you'd map 'X' to deliver a small electric shock. ;-)
Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by westurner on Saturday January 07, 2023 @05:41PM (#34293777)
> Mapping to 'x' is dangerous since on a system where you don't have your vimrc you'll get the original behavior of 'X'.

Which is still to prompt? A person could take their chances

Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by jjallen on Saturday January 07, 2023 @10:13AM (#34288699)
Yeah, thanks for this. `:wq` is pretty fast to write. I think I will stick to it.
Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by sodapopcan on Saturday January 07, 2023 @10:18AM (#34288750)
Or, as other have pointed out, just use `ZZ` which is even easier and equivilant to `:x`.
Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by sshine on Saturday January 07, 2023 @10:59AM (#34289244)
:q, if you didn’t make a change, is even shorter.
Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by jjallen on Saturday January 07, 2023 @11:42AM (#34289725)
If you do this half the time you will have forgotten that you have edited the file and won't be able to exit
Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by sshine on Saturday January 07, 2023 @03:55PM (#34292673)
If I forgot I had edited a file and I’m leaving it as if I hadn’t, I will want to know.
Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by sodapopcan on Saturday January 07, 2023 @11:18AM (#34289446)
It's not shorter—there is an implied `<cr>` at the end there and as you have it written it's the same length. Also, if you did make a change, `:q` will yell at you. If that's what you want, though, that's totally cool.

The advantage of `ZZ` is that it can be used as a general "close this window" command. It'll work on unmodifiable buffers as well without complaining.

Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by shp0ngle on Saturday January 07, 2023 @07:59PM (#34294869)
:wq just makes more sense to me, it’s “command: write, quit”

ZZ is just.. random?

Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by sodapopcan on Sunday January 08, 2023 @01:05AM (#34296521)
Sure, but we're talking Vim here. Is that more random than `"0p`? Or `ctl-o`? Or `ctl-6`? Mnemonics are important for operations we only perform a few times per day or every other day or less. But we're talking about a _built-in_ mapping for an operation that is performed probably as much as 1000 times per day, give or take. Convenience beats out mnemonics here because you don't need them (if you care to use it).

I also think the bikeshed should be lime green :)

Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by shp0ngle on Monday January 09, 2023 @05:34AM (#34308849)
It’s fine, it’s vim and it’s all random, but I just can never remember ZZ so much as I can wq. That’s all
Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by ablob on Saturday January 07, 2023 @10:44AM (#34289043)
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 wh... by wayne on Saturday January 07, 2023 @10:47AM (#34289081)
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 wh... by chasd00 on Saturday January 07, 2023 @11:08AM (#34289349)
I did this same thing on a large programming assignment in college. I’m 46 and can still remember the way the lab smelled and what the people sitting next to me were wearing the moment it happened.
Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by mattkrause on Saturday January 07, 2023 @12:53PM (#34290613)
If your TA was named Matt and a bit skeptical/sarcastic about this, I am once again very sorry!

https://news.ycombinator.com/item?id=34290590

Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by lucb1e on Saturday January 07, 2023 @02:33PM (#34291725)
I get annoyed by ":W is not a valid command" errors and aliased it, and that's not even dangerous to get wrong, just have to retype ":w". Why be so careful instead of just aliasing it?

vimrc excerpt:

    command Wq wq
    command WQ wq
    command W w
    command Q q
    command Bd bd
    cnoreabbrev q1 q!
I hate having to get the shift key timing correct so much that I also aliased : to ; for commands, but that's more radical and gets me into trouble on remote systems that are not my own, not sure if I recommend it. I'd recommend vim to change the default for everyone, though (fat chance, I know).

Another annoying thing in vim is whatever the heck Q does. Try to type :q, fail, retry, and now suddenly you have an extra window to close or something. Solution: nnoremap Q <nop>

Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by hcs on Saturday January 07, 2023 @03:37PM (#34292484)
I used to use the W alias whenever I noticed myself doing it on a new setup, but I haven't had to do it recently. I suspect my "slow on the shift" issue was due in part to the lousy keyboards I used to use.
Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by kqbx on Saturday January 07, 2023 @10:48AM (#34289095)
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 wh... by freedomben on Saturday January 07, 2023 @12:42PM (#34290492)
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 wh... by jpavel2 on Saturday January 07, 2023 @04:48PM (#34293238)
This was in 2014. Since then, Vim has added non-obsolete encryption algorithms (some provided by libsodium), used by default.
Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by raydiatian on Saturday January 07, 2023 @01:18PM (#34290860)
This is different from :x though
Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by isbjorn16 on Saturday January 07, 2023 @01:34PM (#34291030)
I think their point is sometimes their left pinky is a bit lazy and won't get off the fucking shift key
Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by raydiatian on Saturday January 07, 2023 @02:44PM (#34291846)
I’ve been a vim (and :x) user for about a decade, and have never once faced this issue. I don’t think I’m a particularly exceptional person, so I tend to suspect my experience isn’t far from average.

In any case, if you’re using vim or the like to edit files without buffering, source control, or backup, I get that it sucks but that footgun had your name on it from the start.

Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by ajford on Saturday January 07, 2023 @02:50PM (#34291912)
I've been a vim user for 15 years and I still often type `:Q` and `:W`. Everyone types differently and some people make mistakes.

Your blaming the victim instead of the software.

Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by raydiatian on Saturday January 07, 2023 @03:47PM (#34292604)
What parent @waisbrot is saying seems uncommon (the source of this whole conversation), but granted, perhaps common enough (or is it instead worrisome enough) that nvim community took it out.

I still type :Q and :W as well, but that is not what is being discussed.

Have you ever irrevocably bricked your system, as @waisbrot mentioned they have twice, from typing :W or :Q? Have you ever bricked your system from typing :X? If so, that isn’t a “use :x vs :wq” problem, that’s seems more of a use common sense problem.

Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by mega_dingus on Saturday January 07, 2023 @04:11PM (#34292857)
OP said exactly "I've twice encrypted my file with password like `cd tmp`"

Not sure how you get "irrevocably bricked your system" from "encrypted my file", but you do you, I guess

You should also let the OP do the OP. They said they made a mistake. Simply, without complaining, and they do something else now. It's that simple

Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by raydiatian on Saturday January 07, 2023 @04:42PM (#34293173)
Parent (not OP) said more exactly

> I've twice encrypted my file with password like `cd tmp`, then saved the config file, breaking my system.

I get “irrevocably bricked system” from the fact that they “broke their system” and I am inferring it could only be something worth mentioning if it were irreversible.

I originally was trying to point out that parent was off-topic, because :x and :X are different. But a fleet of downvotes flooded in, so I defended my viewpoint for the catharsis.

Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by isbjorn16 on Saturday January 07, 2023 @02:57PM (#34291989)
Me either, but that's because I type `:wq!` every single time instead. I'm not one of those who is afraid of typing more than a single character so I don't care if it's actually 3 I'm hitting. I am someone whose entire brain comes to an absolute crash if I type "wq" and it's asking me if I want to save over a RO file. It's like having a belt loop or pocket catch on a door handle and I despise it.

So, `:wq!`, or as I call it "write the fucking file and quit, _with feeling_"

Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by an-honest-moose on Saturday January 07, 2023 @02:57PM (#34291995)
The only reason the footgun is there is because vim put it there. Seems reasonable to me to be frustrated by that.
Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by raydiatian on Saturday January 07, 2023 @03:34PM (#34292444)
Then upgrade to nvim like everybody else idk
Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by jgb1984 on Saturday January 07, 2023 @03:58PM (#34292701)
Some people value stability and gvim. I don't consider nvim an upgrade, it's just a fork with different priorities which may or may not suit you. I continue to use vim and gvim.
Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by avbanks on Saturday January 07, 2023 @04:18PM (#34292930)
The one gripe I gave with neovim is the stability.
Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by the_fury on Saturday January 07, 2023 @01:52PM (#34291263)
It is, but accidentally hitting capslock instead of shift when hitting the colon is extremely easy to do.
Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by drdaeman on Saturday January 07, 2023 @02:05PM (#34291410)
Caps Lock is that key that's best replaced with Ctrl? ;)
Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by still_grokking on Saturday January 07, 2023 @03:22PM (#34292314)
I like Compose on CapsLock more.
Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by MayeulC on Saturday January 07, 2023 @03:48PM (#34292617)
Only for Emacs users. Vim users generally replace it with Escape.
Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by bombela on Saturday January 07, 2023 @04:24PM (#34292993)
Except that vim was designed on a keyboard with the Ctrl key at the place of your current capslock (for most keyboards, Japanese still have Ctrl at the "right" plac).
Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by vasac on Sunday January 08, 2023 @08:01AM (#34298753)
Why not both ;) - ESC when tapped, CTRL as a modifier key when pressed together with some other key.
Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by MayeulC on Monday January 09, 2023 @12:09PM (#34312683)
Good idea! Though aborting a Ctrl-C could close a dialog window :/
Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by pxx on Sunday January 08, 2023 @12:07PM (#34300835)
I'm a vim user and replace it with Ctrl. It's much more useful and you can use ^[ to get Escape.
Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by tomcam on Saturday January 07, 2023 @03:55PM (#34292680)
What the Lord intended
Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by dotancohen on Monday January 09, 2023 @01:03AM (#34307320)
I like to have Caps Lock cycle the last two used keyboard languages. A necessity when there are five designated on the keyboard!
Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by Asooka on Saturday January 07, 2023 @11:27AM (#34289560)
How I've dodged that in the decades of using vim, I don't know. Though these days I roll with space for entering command mode, so the danger is nil.

nnoremap <space> :

Has done wonders for my fingers.

Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by cratermoon on Saturday January 07, 2023 @11:35AM (#34289650)
That's a really bad affordance. It makes it possible for the user trying to do something non-destructive (only write if there are changes) to accidentally destroy and replace the file.
Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by cassepipe on Saturday January 07, 2023 @11:46AM (#34289766)
The only time it has happened to me, I saw a weird prompt and I understood right away. I had almost forgotten than `:wq` was a thing
Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by talex5 on Saturday January 07, 2023 @12:13PM (#34290145)
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)

Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by mattkrause on Saturday January 07, 2023 @12:51PM (#34290590)
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!

Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by BossingAround on Saturday January 07, 2023 @01:16PM (#34290840)
What did you apologize for?

In any case, switching an editor because someone misunderstood :x vs :X (and didn't bother to read what the editor was asking next) seems like a bit of an overreaction to me.

Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by nequo on Saturday January 07, 2023 @01:22PM (#34290902)
Probably apologized for dismissing the first student who went to them rather than taking him seriously.
Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by mattkrause on Saturday January 07, 2023 @02:21PM (#34291601)
He was legitimately confused and panicked and we could have been more understanding (especially since this turned out not to be a one-off thing). It’s good to be kind.

The editor thing wasn’t a big deal: a few minutes of “Beware :X! If you no longer trust vi, feel free to use emacs or nano, which are also installed on our system. They work a bit differently [details, resources]. You can write your code locally too, but if so, make sure it runs on our system with the autograder. Here are a few options for that too.”

Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by canadaduane on Saturday January 07, 2023 @04:50PM (#34293266)
It sounds like the "sluggish ssh connection" may have played a role here--imagine pressing ":X" like you think you should, but nothing happens, so you press enter a few times to see if the console is responsive.
Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by indigodaddy on Saturday January 07, 2023 @02:49PM (#34291904)
Yep with shift-zz you don’t have to worry about this (I don’t think, even if you do shift-xx by mistake I don’t think that does anything— although haven’t tried)
Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by evilbob93 on Monday January 09, 2023 @12:31PM (#34313006)
I think i was 40 years into my usage of vi when i learned that ZQ was a thing. I bet someone else learns it right here.
Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by brimwats on Monday January 09, 2023 @03:18PM (#34315399)
it's me, just learned it
Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by pavlov on Saturday January 07, 2023 @12:17PM (#34290201)
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.”
Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by survirtual on Saturday January 07, 2023 @12:25PM (#34290284)
I don’t know, I grew up with IDEs and came into console based editing much later in my programming life. It is so much better when working with multiple systems over ssh, especially if modifying linux at all, writing drivers, etc.

It is a huge learning curve, but the ease of remote editing and the speed increase is really incredible. Being able to rapidly move around a file with just a keyboard is a super power, but it just takes muscle memory which means a lot of practice and time.

It may or may not be worth it, but it definitely is not a cultist offering. There is a large value add.

Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by avgcorrection on Saturday January 07, 2023 @12:50PM (#34290577)
Harsh but not unwarranted. What a bizarre keybind.
Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by pxmpxm on Saturday January 07, 2023 @01:54PM (#34291292)
I like vi and use it daily, yet fully agree with that statement.
Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by JoyfulPanda on Saturday January 07, 2023 @06:24PM (#34294145)
better alternative is to use `ZZ' then
Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by otherflavors on Sunday January 08, 2023 @02:00AM (#34296786)
posix vi, ovi and nvi lack an X command
Re:Tell HN: Vim users, `:x` is like `:wq` but writes only wh... by KomoD on Sunday January 08, 2023 @07:48AM (#34298654)
Oh, well that's good to know, I guess I'll stick to `:wq` whenever I use vim