3 ms·
I hit :w so reflexively and regularly in working files that swap files only occasionally saves my butt: when I've done substantial work in a new buffer that I h
by wwweston 6y ago
I hit :w so reflexively and regularly in working files that swap files only occasionally saves my butt: when I've done substantial work in a new buffer that I haven't figured out how to name yet and there's a crash.
This happens just often enough that I have to regard it as useful, but it's also less common than crashes that leave me with swaps to contend with across a dozen files that really were pretty much fine. This is a frequent annoyance.
So: occasional big help vs frequent annoyance.
I don't think the problem is actually swap files themselves, though, but the user experience with them. What vim does is prompt you to choose what to do before you've even had a chance to compare the swap with what's saved, and provides no help with the comparison. What'd be nice is if it gave you some kind of visualization of a diff between the two and then prompted you for a choice.
- lucb1e 6y ago100% agree on that last paragraph. For what it's worth, Vim never crashes on me. For me swap files are mostly helpful with broken connections, killed VMs that apparently still had a vim session open in a faraway terminal, or other such situations.
- lloeki 6y ago> I don't think the problem is actually swap files themselves, though, but the user experience with them. Agreed, the UX is 99% the reason of me hating swap files. More often than not I choose recover, only to discover the diff is literally null. Come on, you could not check for that before interrupting? And then in any case you have double the annoyance with that recovered buffer as the old swap remains and you have to delete it or you get the warning again on the next open. It’s kind of like changing branches with git and then back again, vim notices the time stamp of an opened file changed vs the last buffer save, lets you change the file but complains on :w that the file “changed” outside, yet is unable to a) show you a diff of current buffer vs current file, nor b) realised that the filesystem state vs buffer state at last save (which vim fully knows about) produces a null diff, so the buffer changes are safe to write.
- lucb1e 6y ago> only to discover the diff is literally null. Note that you can save the trouble of running diff by watching for the message "Buffer contents equals file contents." Only when they're different, you'll want to write the file to another place and diff it. What bugs me a lot is that, even if the contents are equal, it doesn't cleanup the swap file... is there maybe a command for that so I don't have to go back to my terminal, manually remove .<filename>.swp, and open up vim again?
- lloeki 6y agoI don’t think you even need to write, I have this shortcut[0]: nmap <leader>d :w !diff -u % -<CR> It writes the buffer’s content to diff’s stdin, and diff gets passed the filename (hence the current on disk content) to compare vs stdin (hence the current buffer content). Only I wish it were run automatically by vim in aforementioned cases before whining (case a: recover, run the above, if no diff stop complaining; case b: rewind til last save, run the above, if no diff then replay and save without complaining) [0]: https://github.com/lloeki/vimfiles/blob/9c50f3be60e536518beb5d80637691c2207bf1ab/vimrc#L124 https://github.com/lloeki/vimfiles/blob/9c50f3be60e536518beb...
- JNRowe 6y ago> I hit :w so reflexively and regularly in working files that swap files only occasionally saves my butt I'm definitely one of those people too, and while I don't disable swap files I do depend heavily on `persistent-undo`. It literally changed the way I work when it was introduced. To some extent I treat it as an extension to swapfile functionality as it also operates across broken sessions(intentional or not). > [...] the user experience with them Christian Brabandt's Recover.vim¹ is a huge improvement for those few times when you do actually want to work with a swap file. General recommendation to poke around in his other repositories too, as he has written a heap of extremely useful vim things. Edit: Especially unicode.vim² which improves `ga` no end, csv.vim³ which feels like magic, NrrwRgn⁴ for fellow emacs refugees, and ... ¹ https://github.com/chrisbra/Recover.vim https://github.com/chrisbra/Recover.vim ² https://github.com/chrisbra/unicode.vim https://github.com/chrisbra/unicode.vim ³ https://github.com/chrisbra/csv.vim https://github.com/chrisbra/csv.vim ⁴ https://github.com/chrisbra/NrrwRgn https://github.com/chrisbra/NrrwRgn