Live data from Hacker News

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

news.ycombinator.com

171–180 of 279 posts

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

#171
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 get annoyed by ":W is not a valid command" errors and aliased it, and that's not even dangerous to get wrong, just have to retype ":w". Why be so careful instead of just aliasing it?

vimrc excerpt:

    command Wq wq
    command WQ wq
    command W w
    command Q q
    command Bd bd
    cnoreabbrev q1 q!
I hate having to get the shift key timing correct so much that I also aliased : to ; for commands, but that's more radical and gets me into trouble on remote systems that are not my own, not sure if I recommend it. I'd recommend vim to change the default for everyone, though (fat chance, I know).

Another annoying thing in vim is whatever the heck Q does. Try to type :q, fail, retry, and now suddenly you have an extra window to close or something. Solution: nnoremap Q

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

#172

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.

Never liked ":x" construct since I started to use vi. Always used ":wq". Now realising, it had a hidden benefit. Good for me.

So what's your hidden benefit

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

#173

:update is like :w but only writes when changes are made. While we're at it :earlier and :later are undo/redo but instead of using an undo stack they use change points in time, so your undo history is never overwritten :)

:earlier 30s is such a life saver when you've messed up the standard undo/redo order (u and ctrl+r).

I need it so rarely that I have a hard time remembering what the command was again whenever I need it. Needed it a few weeks ago, so now it's at the front of my mind again :D

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

#176

By the way, why does visudo sometimes give me another editor (like nano) on a new system. Isn't "vi" supposed to mean "vi"?

This is why I always 'sudo vim /etc/sudoers'. I don't want to have to deal with using and exiting nano somehow (that I need to edit sudoers means that the system isn't properly set up, so odds are that there won't be vim configured as default editor yet either).

Of course, one should make one's own risk assessment here. It's not as though visudo can read your mind and prevent you from locking yourself out or something, so if you are on a system where you can't fall back to modifying the file on the (virtual) disk directly, you might want to first open a second shell and test your changes after saving and before quitting either vim or visudo.

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

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

Yep with shift-zz you don’t have to worry about this (I don’t think, even if you do shift-xx by mistake I don’t think that does anything— although haven’t tried)

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

#179

Earlier quoted context omitted.

I think their point is sometimes their left pinky is a bit lazy and won't get off the fucking shift key

[dead]

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.

Post reply on HN