Hacker News new | past | comments | ask | show | jobs | submit login

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.


This was in 2014. Since then, Vim has added non-obsolete encryption algorithms (some provided by libsodium), used by default.


This is different from :x though


I think their point is sometimes their left pinky is a bit lazy and won't get off the fucking shift key


[dead]


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.


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.


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


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.


The only reason the footgun is there is because vim put it there. Seems reasonable to me to be frustrated by that.


Then upgrade to nvim like everybody else idk


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.


The one gripe I gave with neovim is the stability.


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_"


It is, but accidentally hitting capslock instead of shift when hitting the colon is extremely easy to do.


Caps Lock is that key that's best replaced with Ctrl? ;)


Only for Emacs users. Vim users generally replace it with Escape.


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).


Why not both ;) - ESC when tapped, CTRL as a modifier key when pressed together with some other key.


Good idea! Though aborting a Ctrl-C could close a dialog window :/


I'm a vim user and replace it with Ctrl. It's much more useful and you can use ^[ to get Escape.


I like Compose on CapsLock more.


I like to have Caps Lock cycle the last two used keyboard languages. A necessity when there are five designated on the keyboard!


What the Lord intended


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.


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


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.

(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!


[flagged]


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.”


Probably apologized for dismissing the first student who went to them rather than taking him seriously.


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)


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.


it's me, just learned it


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`.


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. ;-)


  cmap X x
  :help X
> 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.


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.


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


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.


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


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.


The endless battle continues, be brave


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.


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.


i did an alias mapping :Wq to :wq


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.


Yeah, thanks for this. `:wq` is pretty fast to write. I think I will stick to it.


Or, as other have pointed out, just use `ZZ` which is even easier and equivilant to `:x`.


:q, if you didn’t make a change, is even shorter.


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.


If you do this half the time you will have forgotten that you have edited the file and won't be able to exit


If I forgot I had edited a file and I’m leaving it as if I hadn’t, I will want to know.


:wq just makes more sense to me, it’s “command: write, quit”

ZZ is just.. random?


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 :)


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


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


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


Oh, well that's good to know, I guess I'll stick to `:wq` whenever I use vim


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.


I like vi and use it daily, yet fully agree with that statement.


Harsh but not unwarranted. What a bizarre keybind.


better alternative is to use `ZZ' then


posix vi, ovi and nvi lack an X command




Consider applying for YC's Spring batch! Applications are open till Feb 11.

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

Search: