back

by thisisauserid·4y ago·view on hn ↗
I can't be the only one to use :x instead of :wq but I never see it in tutorials. It's 50% fewer keys!
2 comments
ZZ also does the trick, but I always do :wq out of habit. After all, you only write and quit once per file.
ZZ is the same as :x which are both what I would normally want to do - only write if changed.

I would use :wq! to overwrite readonly files more than I would use :wq The only use case I can think of writing when not changed is if there is a process watching the file that I want to trigger.

I think the problem with teaching people how to save and quit in vim is that there are so many ways they might want to do it and nobody wants to dumb it down to a single default. It is a bit like how Zig doesn't have a simple print macro because in real code do you want your output buffered or unbuffered, etc.

ZZ and ZQ are both very nice.

On the note of saving/quitting and things not being mentioned enough, I only recently learned about :up to only save the file if there were actually changes (probably short for "update). Saves some time, especially with remote files, if you're one to save a lot and not remember if you saved recently already. I think this is closer to how emacs saving works by default. I bind space-f-s to save files, and tend to use that more than :w or similar, so in my case I just updated what that keybind did.

I have mapped F2 to save and F3 to save and quit ;)

Probably I should add something about alternate ways, there's another comment with more variations that I didn't cover.