Live data from Hacker News

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

news.ycombinator.com

131–140 of 279 posts

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

#131
post #83
post #63

Earlier quoted context omitted.

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

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

#132
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 in vim does not have the meaning normal people associate with a normal text editor.

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

#134

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.

Ctrl+Z sends a signal to the process which is purely advisory. The process can do anything or nothing. Vim's extensive and unreadable signal handling logic can be gazed upon at: https://github.com/vim/vim/blob/master/src/os_unix.c

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

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

No need to test, it's documented: https://neovim.io/doc/user/editing.html#ZZ

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

#137
post #48

See, that's why even though I'm a terminal user first and foremost, I really like the discoverability of GUIs, and that's where a good GUI is unbeatable by CLI. This would have just been an entry "Save if needed" in the File menu, right below "Save", and users would probably find it by accident while looking at the menu, even while not actively looking for new ways to save a file. (Not getting into the fact that a we…

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

`which-key` is great. But that is already ubiquitous through the standard top-left drop-downs in a GUI:[1] Press `Alt-F` (File, underlined F), all options drop down, then `S` (Save, underlined S).

[1] Or a standard GUI. Emacs can be run as a GUI (not terminal).

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

#138
post #48

See, that's why even though I'm a terminal user first and foremost, I really like the discoverability of GUIs, and that's where a good GUI is unbeatable by CLI. This would have just been an entry "Save if needed" in the File menu, right below "Save", and users would probably find it by accident while looking at the menu, even while not actively looking for new ways to save a file. (Not getting into the fact that a we…

I agree that Vim's a mess, but I don't think a good GUI is unconditionally better because you'd need to cut down Vim's gigantic command set in order to make the GUI comprehensible.

Just in this thread we've seen options for: close unless there are changes, discard changes and close, save and close, save if changed and close, and save with encryption and close. These would not be menu items.

In a GUI, you would have close (which would always prompt if there were changes, unless you turned it off globally), save (which wouldn't do anything if there were no changes), and perhaps some extra setting somewhere about an encryption key. Which would mean you'd lose the option to unconditionally save (useful sometimes if you have something watching the file and you're testing), and you'd have an extra dialog box which pops up sometimes. In terms of discoverability, it's unconditionally better, but it's not unconditionally better in all other ways.

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

#139

Earlier quoted context omitted.

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.

That’s not the exact same as Escape.

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

#140
post #51

Earlier quoted context omitted.

Make sure to see this comment about :X encrypting your file instead of exiting https://news.ycombinator.com/item?id=34288446

I can't help but see that argument as post rationalization from people who have bee using :wq their whole life \s Been using :x from the start about 4 years ago and I never accidentally encrypted a file.

Same (but for a longer period of time). I'm kind of surprised people don't know this.
Post reply on HN