A vis plugin that makes backups of current files before saving.
Writes backups to ~/.vis-backups.
This backup folder must exist and you need permissions to write to it.
Call backup.set_directory(path) to save backups to a different directory.
See below for configuation examples.
Download the repository. One way is with the git CLI:
git clone https://github.com/roguh/vis-backup
Ensure the directory vis-backup/ is next to visrc.lua.
$ ls visrc.lua vis-backup/
Add this line to your visrc.lua to load the backup.lua file:
require('vis-backup/backup')
It may be simpler to copy the backup.lua file adjacent to visrc.lua and run require('backup').
visrc.lua can be found at XDG_CONFIG_HOME/vis or $HOME/.config/vis.
If not set, use :help for instructions on how to initialize vis.
You may also install it in Lua's path.
See documentation about the require function.
If the backup.lua file is found in another directory, use the different path:
backup = require('plugins-directory/vis-backup/backup') -- Call this if the backup directory doesn't exist backup.set_directory(os.getenv('HOME') .. '/.cache/bak')
$ tree
.
├── vis-backup
│ ├── README.md
│ └── backup.lua
└── visrc.luaTo configure this module, you may modify the backup table, for example:
backup = require('backup') backup.byte_limit = 500000 backup.set_directory(getenv('HOME') .. '/.cache/vis-bak')
Default configuration:
backup.set_directory(os.getenv('HOME') .. '/.vis-backups') backup.get_fname = backup.entire_path_with_double_percentage_signs backup.time_format = '%H-%M-' -- 1MB backup.byte_limit = 1000000
Add this to your visrc.lua:
backup.get_fname = backup.entire_path_with_double_percentage_signs_and_timestamp
Add this to your visrc.lua:
backup.get_fname = function(_, filepath) return filepath .. '~' end
filepath will not be nil.
This should write a copy of your file to filename~ before saving it.
Files longer than backup.byte_limit bytes are not backed up.
Default is 1MB.