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
Tell HN: Vim users, `:x` is like `:wq` but writes only when changes are made
41–50 of 279 posts
Re: Tell HN: Vim users, `:x` is like `:wq` but writes only when changes are made
#42Re: Tell HN: Vim users, `:x` is like `:wq` but writes only when changes are made
#43Re: Tell HN: Vim users, `:x` is like `:wq` but writes only when changes are made
#44Re: Tell HN: Vim users, `:x` is like `:wq` but writes only when changes are made
#45I 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.
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
#46Keybinds (in normal mode): Shift + ZZ -> :x (save only if needed and quit) Shift + ZQ -> :q! (quit without saving)
Re: Tell HN: Vim users, `:x` is like `:wq` but writes only when changes are made
#47Why 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.
Re: Tell HN: Vim users, `:x` is like `:wq` but writes only when changes are made
#48This 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
#49While 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 :)
Re: Tell HN: Vim users, `:x` is like `:wq` but writes only when changes are made
#50I 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.