Live data from Hacker News

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

news.ycombinator.com

101–110 of 279 posts

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

#101
I map 'S' to this in my .vimrc:

    nmap S :wall
which saves all changed buffers into their respective files.

It is probably the single most productive customization in my .vimrc file. I save my files very often, and I usually have multiple files and buffers open. 'cc' is an alias for the old 'S', so I don't lose much.

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

#104
for me, I don't want it to write only when there are changes. I want it to error out if I try to quit without saving changes so I go and figure out if I changed something by accident before I save it and I want it to write specifically when I tell it to write. This cuts down on so many problems, at least in my use cases.

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

#105

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 a vi keybind, so the keymap wasn't even that exhausted yet!

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

#106
post #3

I had a CS prof years ago tell us all the only thing we needed to know about vi(m) was the dammit key As in "escape-q-dammit"

Just throwing another one out there: `Ctrl + [` instead of `Esc` to save some finger travel.

Too fundamental of a key to even be a combination IMHO. I terminate each edit operation by it, like a dot at the end of a sentence, it needs to be a half a second operation so I can spend most of my time in normal mode.

I just remap Caps Lock to Esc system wise (a setting in both Linuxes and MacOs) and use both shift for Caps Lock (setting on Linux, Idk about MacOS)

I have always found the "jk" solution quite elegant although I don't use it

The benefit of using it system wise is that it then works with all programs that have a vi mode (zsh, gdbtui, etc.)

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

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

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

#108
post #3

I had a CS prof years ago tell us all the only thing we needed to know about vi(m) was the dammit key As in "escape-q-dammit"

Just throwing another one out there: `Ctrl + [` instead of `Esc` to save some finger travel.

You can escape with alt too

https://news.ycombinator.com/item?id=34168031

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

#109

I am surprised it is not already mentioned in the comments, but I personally cannot use an editor that doesn't automatically write changes when I am done typing. I just forget to save and wonder why the app I am working on did not change. So my (neo)vim setup uses a plugin like `Pocco81/auto-save.nvim`. This solves the problem mentioned by OP because I can just `:q` anytime.

I really hate autosave. I like using saving like a checkpoint where i have the ultimate undo button by ditching the unsaved changes. Second, in a large Excel file, the auto save is constantly slowing me down because there’s a slight hang after every cell change.

> I really hate autosave. I like using saving like a checkpoint where i have the ultimate undo button by ditching the unsaved changes.

Although I don't use autosave, I don't think it matters that much with vim because you can always use undotree[0]

0: https://github.com/mbbill/undotree

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

#110

I learned early on that the easiest way to quit Vim without saving was ctrl-Z and then kill -9 %1

You could just reboot.

Have to post this gem [0] about creative ways to exit Vim

0: https://github.com/hakluke/how-to-exit-vim

Post reply on HN