Tell HN: Vim users, `:x` is like `:wq` but writes only when changes are made
537 points`:x` leaves the modification time of files untouched if nothing was changed.
:help :x
Like ":wq", but write only when changes have been made.
Comments (270) 59 threads
Show all comments
Showing thread 4 of 59
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 well programmed Save function would, IMO, not do anything if there are no changes, i.e. if I was the one writing the code, the Save button would be greyed out, or in the case of vim, :wq would not write anything if no changes had been made... but that's a different discussion)
[1]: https://github.com/nvim-telescope/telescope.nvim
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/
In practice (which is what matters, ultimately), most CLI tools don't have this desirable property of "discoverable by accident".
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.
Continue this thread — 1 reply
[1] Or a standard GUI. Emacs can be run as a GUI (not terminal).
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.
both :xa and :wqa work for this though.
No, the command would simply not exist because having so many commands would take up too much screen space.
It saves automatically when you press compile or change focus to another window. This is how both VSCode and Intellij work. Together with a local history that allows you to go back in time to any point earlier during the day.
Writing things in stone or reverting to older state is something reserved for git.