0

I'm writing a script to ensure that everything I work on on my system is committed, pushed to Git etc. I'd also like to check if there are any vim swapfiles active (either in a running Vim, or from abnormal exit).

How can I check? Short of starting a vim for each tracked file and somehow checking if vim complains about recovery / swap active.

Even nicer would be to check from the outside if there are modified buffers in any running vim instance, but that doesn't seem too feasible

NOTE I'm keeping all my swapfiles in a separate dir (:set directory=), so it's hard to associate swaps with reals (probably requires parsing viminfo)

5
  • What about setting :h 'directory' to something like ~/.vim/swap/ and then checking for the existence of files in this directory (ls, find, or whatever you are comfortable with)?
    – statox
    Apr 9 '21 at 9:26
  • I already have it set to ~/.vim/bakfiles (used for all undo, baks, swp's etc), but there are many inactive swapfiles left over even when no vim running
    – usretc
    Apr 9 '21 at 9:29
  • Ah my bad, I use noswapfiles and I was sure that vim deletes the swapfile when it's done with a buffer.
    – statox
    Apr 9 '21 at 9:32
  • It might delete swaps by default, I don't remember -- mine is heavily customized over a long time
    – usretc
    Apr 9 '21 at 9:33
  • Swapfiles are supposed to disappear when vim exits correctly. It might be worth using a double-/ in directory, though, as that gets you full file-path information.
    – D. Ben Knoble
    Apr 9 '21 at 12:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.