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.
> 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.
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.
> 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.
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.
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_"
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).
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. :)
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.
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>
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.
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.
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!
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.”
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.
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)
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. ;-)
> 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.
Besides, wouldn't that form of intentionally aversive conditioning actually boost the learning rate and create hyperassociations to the behavior your're attempting to stimulus extinct or just learn over?
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.
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
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.
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.
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.
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.
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).
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.
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.”
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.
After that, I switched to `:wq` (and sometimes `:w` `:q`) which is much safer against over-typing.