I use git or icloud dropbox for cloud backup. I really don’t see any need for vim backup files. That file will also affect grep, which is too inconvenient.
I have a special script to handle Vim backup files. Depends on Python 3 and mlocate. Backup files will be deleted in two situations: the original file has not been modified for a long time; the original file no longer exists.
It is not recommended to disable the backup function. Although persistence is eliminated now, multiple backups of data are always safer.
Let’s post a copy of the code here:
#!/usr/bin/env python3
# fileencoding=utf-8
'''从列表中读取备份文件(*~)列表,并检测原文件是否存在;若不存在则删之'''
import sys, os
import subprocess
import datetime
if len(sys.argv) == 1:
db = None
elif len(sys.argv) == 2:
db = sys.argv[1]
else:
sys.exit('argument error')
if db:
f = subprocess.getoutput("locate -d '%s' -e -b '*~' 2> /dev/null" % db).split('\n')
else:
f = subprocess.getoutput("locate -e -b '*~' 2> /dev/null").split('\n')
def filter(i):
if not os.path.isfile(i[:-1]):
return True
try:
atime = datetime.datetime.fromtimestamp(os.stat(i).st_atime)
except FileNotFoundError:
return False
now = datetime.datetime.today()
interval = datetime.timedelta(days=30)
if now - atime > interval:
return True
return False
for i in f:
if i.endswith('~') and os.access(os.path.split(i)[0], os.W_OK):
if filter(i):
try:
print("删除", i)
try:
os.unlink(i)
except FileNotFoundError:
print(i, '在被删除前消失了:-(')
# print(i)
except:
print(i+': error'+repr(sys.exc_info()), file=sys.stderr)
The file name starts with - (can be mistaken for parameters) (this is a classic pitfall)
The file name does not contain .
The correct command is rm -f -- *~.
The above only answers the superficial part of this question (Question Y). Regarding the essential goal of dealing with vim’s temporary files (X problem), please also ask more vim experts on this site represented by @evian to answer
I use git or icloud dropbox for cloud backup. I really don’t see any need for vim backup files. That file will also affect grep, which is too inconvenient.
I have a special script to handle Vim backup files. Depends on Python 3 and mlocate. Backup files will be deleted in two situations: the original file has not been modified for a long time; the original file no longer exists.
It is not recommended to disable the backup function. Although persistence is eliminated now, multiple backups of data are always safer.
Let’s post a copy of the code here:
Join
Try it and see if it works
You can’t avoid deleting it this way:
-
(can be mistaken for parameters) (this is a classic pitfall).
The correct command is
rm -f -- *~
.The above only answers the superficial part of this question (Question Y). Regarding the essential goal of dealing with vim’s temporary files (X problem), please also ask more vim experts on this site represented by @evian to answer