Live data from Hacker News

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

news.ycombinator.com

111–120 of 279 posts

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

#111
post #10

You can also type ZZ (no colon) while in normal mode to exit and save. This also appears to only write when changes have been made (according to some testing in neovim on my local machine).

> You can also type ZZ (no colon) while in normal mode to exit and save.

That's insane. What if you need to type the following words in all caps?

     DRIZZLE
     GRIZZLY
     BUZZARD
     PIZZAZZ
The last would make that command from normal mode particularly annoying. Unless you meant when not in input mode... duh.

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

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

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

#113
post #76
post #70

Earlier quoted context omitted.

Can't you use :q and then :x instead of :q then :wq ?

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!

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

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

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

#115
post #84

Earlier quoted context omitted.

> even though I'm a terminal user ... I really like the discoverability of GUIs, and that's where a good GUI is unbeatable by CLI. CLI has poor discoverability? Sure; but even on the terminal, discoverability can still be good: A couple of nice examples of discoverability in keyboard-focused programs: - emacs' which-key[0]; there's a vim port[1] too. This shows you (some) of the available keybindings for the next inp…

Yeah, you're right that CLI discoverability can still be good , but that's the same " can " than when talking about how "Electron apps can be responsive and fast" when putting VSCode as the prime example... yes, they can , but only with a great deal of extra effort from the devs, compared to the instantaneous visual feedback that a new entry provides on a GUI. In practice (which is what matters, ultimately), most CLI…

Slight nit-picking; maybe the distinctions are useful for this conversation:

I'd use "CLI" more precisely to refer to command-line invocation of programs (using some shell like bash, fish, or powershell).

For programs like vim or nano, I think "TUI" (text-based UI, or sometimes terminal UI) is more suitable.

> yes, they can, but only with a great deal of extra effort from the devs, compared to the instantaneous visual feedback that a new entry provides on a GUI.

Right.

I'd say instantaneous visual feedback is what helps discoverability. Both menus in a GUI, and the menus in a TUI like in the examples above, exhibit that.

But, I wouldn't go so far as to say that a GUI menu is inherently discoverable. e.g. The image editor GIMP doesn't have good discoverability, despite being a GUI program with menus.

Whereas e.g. nano is a TUI program, but its essential features are much more discoverable compared to vim. The new tmux-alternative zellij borrows the same "show the keymap at the bottom" feature.

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

#116
post #10

You can also type ZZ (no colon) while in normal mode to exit and save. This also appears to only write when changes have been made (according to some testing in neovim on my local machine).

> You can also type ZZ (no colon) while in normal mode to exit and save. That's insane. What if you need to type the following words in all caps? DRIZZLE GRIZZLY BUZZARD PIZZAZZ The last would make that command from normal mode particularly annoying. Unless you meant when not in input mode... duh.

"Normal mode" ≠ "Insert mode"

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

#117
post #10

You can also type ZZ (no colon) while in normal mode to exit and save. This also appears to only write when changes have been made (according to some testing in neovim on my local machine).

> You can also type ZZ (no colon) while in normal mode to exit and save. That's insane. What if you need to type the following words in all caps? DRIZZLE GRIZZLY BUZZARD PIZZAZZ The last would make that command from normal mode particularly annoying. Unless you meant when not in input mode... duh.

He did say in "Normal Mode"

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

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

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 when changes are made

#120

Earlier quoted context omitted.

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 ever…

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

Post reply on HN