sponsor Vim development Vim logo Vim Book Ad

writebackupAutomator : Automatically write a backup on the first write.

 script karma  Rating 12/9, Downloaded by 2183  Comments, bugs, improvements  Vim wiki

created by
Ingo Karkat
 
script type
utility
 
description
DESCRIPTION
Unless you use a revision control system, you have to write backups yourself.
The writebackup.vim plugin makes that a simple :WriteBackup command from
within Vim, but you still have to remember to trigger the backup. The
writebackupVersionControl.vim extension can make up for a missed backup when
you have already made changes to the buffer, but have not persisted them yet,
via :WriteBackupOfSavedOriginal. Still, wouldn't it be nice if Vim detected
that you have made backups of a file in the past, and automatically creates a
new backup - without any action on your side?

This plugin builds on the writebackup.vim and
writebackupVersionControl.vim plugins, and automatically writes a backup on
a day's first write of a file that was backed up in the past, but not yet
today.
This gives you one no-hassle, worry-free backup every day. For many
writebackup.vim use cases (like editing config files distributed all over
/etc/), this initial "good state from the past" backup is the most important
one. (And of course you can still manually trigger additional checkpoint
backups via :WriteBackup as in the past.)

USAGE
Once any backup exists (you can check via :WriteBackupListVersions), a new
backup will be written on each day when you first persist the buffer via
:write, provided that the file has not been modified yet today. (Otherwise,
you would not be able to undo the automatic backup via
:WriteBackupDeleteLastBackup; the automatic backup would keep reappearing
after each :write.) Watch out for file synchronization tools and version
control systems that may silently update the file modification date to today
and therefore prevent automatic backups!
For this and other reasons, it is still a good practice to trigger backups via
:WriteBackup yourself, and just use the writebackupAutomator plugin as a
safety net, for those instances where you forget to backup.
 
install details
INSTALLATION
The code is hosted in a Git repo at
    https://github.com/inkarkat/vim-writebackupAutomator
You can use your favorite plugin manager, or "git clone" into a directory used
for Vim packages. Releases are on the "stable" branch, the latest unstable
development snapshot on "master".

This script is also packaged as a vimball. If you have the "gunzip"
decompressor in your PATH, simply edit the *.vmb.gz package in Vim; otherwise,
decompress the archive first, e.g. using WinZip. Inside Vim, install by
sourcing the vimball or via the :UseVimball command.
    vim writebackupAutomator*.vmb.gz
    :so %
To uninstall, use the :RmVimball command.

DEPENDENCIES
- Requires Vim 7.0 or higher.
- Requires the writebackup.vim plugin (vimscript #1828), version 3.00 or
  higher.
- Requires the writebackupVersionControl.vim plugin (vimscript #1829),
  version 3.21 or higher.
- Requires the ingo-library.vim plugin (vimscript #4433), version 1.007 or
  higher.

INTEGRATION
You can influence the behavior of the writebackupAutomator plugin via the
buffer-local variable b:WriteBackup. When this is 0, no automatic backup will
be done even when previous backups exist. Contrariwise, when set to 1, the
buffer will be automatically backed up even when no backups exist so far.
You can use this variable in autocmds, filetype plugins or a local vimrc to
change the backup behavior for certain file types or files in a particular
location.
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
writebackupAutomator-1.11.vmb.gz 1.11 2020-04-03 7.0 Ingo Karkat - Adapt to the introduction of command aborts in WriteBackupVersionControl version 3.21. *** YOU NEED TO UPDATE to WriteBackupVersionControl (vimscript #1829) version 3.21 or higher! ***
- ENH: "Skip automatic backup; file was already modified today." message is annoying after each :write; Instead, give each message only once per buffer.
writebackupAutomator.vba.gz 1.10 2012-06-11 7.0 Ingo Karkat Never attempt to backup when the current buffer hasn't been persisted yet, but warn in case there are already backup files lying around.
writebackupAutomator.vba.gz 1.01 2012-02-27 7.0 Ingo Karkat Rename b:writebackup to b:WriteBackup to be consistent with the other
configuration variables of the WriteBackup family, and to avoid connotation
with the built-in 'writebackup' setting.*** PLEASE UPDATE YOUR CONFIGURATION ***
writebackupAutomator.vba.gz 1.00 2012-02-16 7.0 Ingo Karkat Initial upload
ip used for rating: 142.132.191.50

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
Vim at Github