Live data from Hacker News

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

news.ycombinator.com

151–160 of 279 posts

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

#151
post #68

I always :q when I didn’t change anything. If I changed something intentionally, :wq and :x are equivalent. If I changed something accidentally, :x won’t catch that, and :q complaining will require me to decide if :q! or :wq is correct. So :x does not fit my workflow of avoiding accidental writes. Just like ZZ does not.

I use :x cus it's one less keystroke. And yes, I still use :q to make sure I don't save in case I changed something by mistake.

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

#152
post #51

Earlier quoted context omitted.

Make sure to see this comment about :X encrypting your file instead of exiting https://news.ycombinator.com/item?id=34288446

I can't help but see that argument as post rationalization from people who have bee using :wq their whole life \s Been using :x from the start about 4 years ago and I never accidentally encrypted a file.

Same. Been using :x for about 20 years. Had no idea there was some similar encryption nonsense.

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

#153
post #107

I became quite an advanced vim user in 1999, during my military service in Italy (I was stationed at the Ministry of Aerial Defense, and working on IT stuff). It's quite incredible and a bit weird that today, in 2023, I can say "Yes, I knew this", despite non having used vim much since ~2012. I would have never guessed I'd be able to recall things like this.

I don't know Vim, my fingers do. More seriously sometimes I'll get a question about how I did/do something, and have to sit at the keyboard and actually perform the action to be able to provide the answer.

A sure sign of a well designed tool imo

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

#154
post #68

I always :q when I didn’t change anything. If I changed something intentionally, :wq and :x are equivalent. If I changed something accidentally, :x won’t catch that, and :q complaining will require me to decide if :q! or :wq is correct. So :x does not fit my workflow of avoiding accidental writes. Just like ZZ does not.

It's funny but I use q when I don't intend to change things and wq in whatever state I'm seeing them and x when I'm working on clean git state.

Honestly it sounds complex, but I don't even think about it and it only struck me reading your comment.

The warning note on q is desirable.

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

#155
Is there a good way to manage saved-but-not-exited vim windows so I don't open the same file twice? I keep running into a problem where I'm editing a dozen files, and then I try to re-open a file I already have opened. Vim gives me a warning about this but my choices are a) tab through all my open windows until I find the right one, or b) open a new editing window and hope that I didn't have unsaved changes in the first one.

Is there a way to have vim just go to the open window? Or is there a better way to manage my windows?

(I'm using MacVim if it makes a difference.)

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

#156
post #65

Earlier quoted context omitted.

In neovim, :X (and cryptography in general) is removed https://github.com/neovim/neovim/commit/85338fe

This is different from :x though

It is, but accidentally hitting capslock instead of shift when hitting the colon is extremely easy to do.

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

#157
post #114

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, this is absolutely horrible. Filing this as yet another item under “Why vim is the worst example of 1970s bullshit UX still recommended by cargo cultists everywhere.”

I like vi and use it daily, yet fully agree with that statement.

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

#159
post #155

Is there a good way to manage saved-but-not-exited vim windows so I don't open the same file twice? I keep running into a problem where I'm editing a dozen files, and then I try to re-open a file I already have opened. Vim gives me a warning about this but my choices are a) tab through all my open windows until I find the right one, or b) open a new editing window and hope that I didn't have unsaved changes in the fi…

setting "nohid" will cause vim to close non-active buffers, so at least then you only need to tab through active buffers. If I run into this situation, I just close all of my open vim windows, saving as needed, but you might have a good use case for many open vim windows.
Post reply on HN