Live data from Hacker News

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

news.ycombinator.com

81–90 of 279 posts

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

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

programs like vim and tmux desperately need a menu which just shows all available commands (including plugins), even if it’s opt-in. AFAIK no such menu actually exists in vim or neovim because of the way some of the commands are hard-coded

Telescope[1] on NeoVim can provide such interface. It is not standard, but telescope is becoming really widespread.

[1]: https://github.com/nvim-telescope/telescope.nvim

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

#82
post #46

Keybinds (in normal mode): Shift + ZZ -> :x (save only if needed and quit) Shift + ZQ -> :q! (quit without saving)

I always use ZZ! It’s so much more convenient to type with one hand

I really like having to use both my hands to perform an irreversible change to disk. Those extra milliseconds let me think through what I’m doing.

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

#83
post #63

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

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

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

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 tools don't have this desirable property of "discoverable by accident".

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

#85
post #71

Earlier quoted context omitted.

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

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

programs like vim and tmux desperately need a menu which just shows all available commands (including plugins), even if it’s opt-in. AFAIK no such menu actually exists in vim or neovim because of the way some of the commands are hard-coded

Check out zellij in place of tmux https://github.com/zellij-org/zellij

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

#87

Keybinds (in normal mode): Shift + ZZ -> :x (save only if needed and quit) Shift + ZQ -> :q! (quit without saving)

> Shift + ZZ That’s a real “geez, our keymap is almost exhausted!” keybind.

Vim has way worse in its defaults. gqq, naturally, formats the current line.

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

#88

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.

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 :

Has done wonders for my fingers.

Post reply on HN