Vim has a nice feature to recover files if previous session was crashed . Vim show something like this when it happened:
Swap file "~/Desktop/.file.txt.swp" already exists!
[O]pen Read-Only, (E)dit anyway, (R)ecover, (Q)uit, (A)bort:
In most cases I recover the file, and its irritating to press r every time vim crashes.
The problem not ends here. Even if the file has been recovered the swap file still exists there, and that prompt appears again.
So each time in such situation, I want to recover silently and delete the swap file.
If you are -certain- that the file on the disk is the correct one and you don't need the "autosaved" information in the swapfile, you can simply type "D" to delete the swapfile. The message will go away and you can continue working.
By default, the swap file is created in the same location as the virtual machine's configuration file, which may either be on a VMFS datastore, a vSAN datastore or a VMware vSphere® Virtual VolumesTM datastore. On a vSAN datastore or a vVols datastore, the swap file is created as a separate vSAN or vVols object.
An SWP file is a swap file created by the Vi text editor or one of its variants, such as Vim (Vi iMproved) and gVim. It stores the recovery version of a file being edited in the program. SWP files also serve as lock files, so no other Vi editing session can concurrently write to the currently-open file.
I haven't tried it, but I think you could use this:
augroup AutomaticSwapRecoveryAndDelete
autocmd!
autocmd SwapExists * :let v:swapchoice = 'r' | let b:swapname = v:swapname
autocmd BufWinEnter * :if exists("b:swapname") | call delete(b:swapname) | unlet b:swapname | endif
augroup end
See :h v:swapchoice
, :h v:swapcommand
, :h v:swapname
and :h SwapExists
Since the swap file should exist as long as your are editing the buffer, I woud rather replace the second autocommand of elmart's answer by
augroup AutomaticSwapRecoveryAndDelete
autocmd!
autocmd SwapExists * :let v:swapchoice = 'r' | let b:swapname = v:swapname
autocmd VimLeave * :if exists("b:swapname") | call delete(b:swapname) | endif
augroup end
Moreover, that would allow you to use :DiffOrig
, when in doubt about the difference between swap and original.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With