Live data from Hacker News

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

news.ycombinator.com

41–50 of 279 posts

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

#41
post #6

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

huh. I'm using ZZ all the time, but I thought it is :wq

You never accidentally used it on an unnamed buffer?

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

#42
I know maybe 4 Vim commands I use to write git commit messages as I was too lazy to change the default editor. :x is one of them. It's funny how different people learn tools differently. I've learnt by googling "Vim basic commands for git commit messages" and never spent any more time on it but apparently this is a revelation for many long time Vim users here.

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

#44

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.

It’s been like that since vi

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

#45

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.

Thanks for this warning.

Even worse for me, because my laptop keyboard has some kind of horrible encoding causing latency on the shift key, so I'm constantly doing :Wq when I type fast enough... Yeah I had the suspicion it was human error - but I've tested using a single finger for shift and w, so it's definitely the keyboard.

[edit]

Looks like that feature is not necessarily built in by default though.

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

#47
post #40

Why would it write if no changes have been made?

Its one of the things about exiting Vim. If you type :q, and there are unsaved changes it will prompt you to save it first and not let you quit. So most people do :wq so that it saves and then quit or do :q! to quit without saving changes. Most people stop using :q.

[deleted]

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

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

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

#50

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.

Yeah, thanks for this. `:wq` is pretty fast to write. I think I will stick to it.
Post reply on HN