Inform HN: Vim customers, `:x` is like `:wq` however writes solely when modifications are made
|
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. |
|
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.
|
|
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.
|
|
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. 😉
|
|
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.
|
|
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.”
|
|
ZZ is only 3 keystrokes as opposed to 4 for 😡 (shift + z + z = 3 and shift + ; + x + enter = 4). It also doesn’t require timing the release of shift before the press of x.
|
|
I use the ‘confirm’ option in my vim config, that way I can always use :q and then get a prompt on what to do if a file’s been changed.
I also map <C-q> to :q to speed things up a bit. |
|
I’ve been using `rm` and `rm -rf` for as long without losing data, but I understand why some people like having a trash can. Different workflows are susceptible to different hazards.
|
|
> 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 input, and a short label. So you don’t have to remember what `SPC h p …` or all the options under `SPC f…`.. but it still helps to recall that `SPC h` is for ‘help’ related commands, `SPC f` for file related commands. – emacs’ magit[2][3]. Magit is so good at discoverability, that I’d rate it as the best tool for using git with. I’ve learned more about git from using it. [0] https://github.com/justbur/emacs-which-key [1] https://github.com/liuchengxu/vim-which-key [2] https://magit.vc/ [3] https://emacsair.me/2017/09/01/magit-walk-through/ |
|
gvim suggest :wqa for “save and quit” in the file menu, which is like “:x” but will save all changed buffers, not just the current buffer.
both :xa and :wqa work for this though. |
|
Sorry, unnamed AND unmodified. My bad.
And actual advantage here is that `ZZ` can be your “quietly quit anything” key. It’ll close quickfix, locationlist, previewwindow, etc without complaining. |
|
Never liked “:wq” construct since I started to use vi, almost three decades ago. Always used “:x”. Now realizing, it had a hidden benefit. Good for me. <pats himself on the back>
|
|
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). |
|
I almost exclusively exit vi using CTRL_W-CTRL-Q.
It’s a 3 finger chord that I use all the time to close vi windows. Makes sense that I’d use it to close the last one too. |
|
Been using vi for just over 25 years now. The only thing I know how to do in emacs is exit 😀 vi uses the ctrl key a ton if you know what you are doing.
|
|
TIL that :wq is like 😡
I only knew about :x. So thus far I’ve only edited with :x, and then used :q! to quit without writing the changes. |
|
I often have the variant with –amend –no-edit in my bash history, so that I press up about two or three times instead of writing anyting at all.
|
|
It’s pretty well-known (a bit less than :wq though).
What most didn’t know (myself included) is that the behavior is slightly different from wq. |
|
A lot of the pain could’ve been avoided if they just wrote somewhere that you need to type ‘:’ or something else to access help/commands when inside of vi/vim
|
|
Vim is from an era when software was written to do exactly what you commanded it, not what you intended. It was your responsibility as a user to learn how to turn your intentions into commands.
|