There are several options related to back up in Vim/Nvim.
backup controls whether to make a physical backup when writing
writebackup make a backup before overwriting a file. If the backup
will be removed when the file is successfully written, unless
is also on. For more info about using
writebackup together, see
:h backup-table. It reduces the risk that you file is destroyed if something
goes wrong when you are writing the file.
backext control the extension used for backup files.
will be appened to the file names and the default is
~. For example, if your
.bak, the backup file name will be
backupdir controls where the backup file will be put. It is a list
of directories to put the backup file separated by comma. The first item in
this option will be used. You must make sure that the backup directory exist,
or you will meet the following error when you want to write a file:
E510: Can’t make backup file (add ! to override)
let g:backupdir=expand(stdpath('data') . '/backup') if !isdirectory(g:backupdir) mkdir(g:backupdir, "p") endif let &backupdir=g:backupdir
There is also an option
backupcopy which need special attention. The value of
backupcopy can be
yes: it will the original file to the backup location and overwrite the original file.
no: it will rename the original file (i.e., move the original file to the backup directory) and write a new file with the same name.
auto: Nvim will choose what works best for you.
Note that for some applications, you may want to set
License CC BY-NC-ND 4.0