sponsor Vim development Vim logo go to HTTPS page Vim Book Ad

writebackupToAdjacentDir : Backup to an adjacent backup directory.

 script karma  Rating 14/5, Downloaded by 685    Comments, bugs, improvements  Vim wiki

created by
Ingo Karkat
script type
Redirect backups made by the writebackup plugin (vimscript #1828) that would
normally go into the original file's directory into an adjacent directory with a
"{dir}.backup" name, if it exists. This allows to use the plugin in places where
backup files would cause problems.

Many customization directories (e.g. /etc/profile.d/) consider all contained
files, regardless of file extension or execute permissions. Creating a
{file}.YYYYMMDD[a-z] backup in there causes trouble and strange effects,
because the backups are used in addition to the main configuration file - not
what was intended! However, putting the backups in the same directory
generally is a good idea - just not for these special directories.

This plugin offers a solution by integrating into the writebackup.vim plugin
so that it checks for a directory with a '.backup' extension (e.g.
/etc/profile.d.backup/), and places the backups in there, in case it exists.
In all other cases, the backup is made in the default directory, as before.

Adjacent backup directories are never created by this plugin; you have to
create such a directory yourself to indicate that backups should be placed in

:WriteBackupMakeAdjacentDir [../..|/path/to/dir] [{prot}]
                Create a backup directory adjacent to the current file's
                directory, or in a parent of that ("..", "../..", etc.), or of
                any passed directory.
                If {prot} is given it is used to set the protection bits;
                default is 0755.

After the adjacent backup directory has been created, just use :WriteBackup
as before.
install details
This script is 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 writebackupToAdjacentDir*.vmb.gz
    :so %
To uninstall, use the :RmVimball command.

- Requires Vim 7.0 or higher.
- Requires the ingo-library.vim plugin (vimscript #4433), version 1.011 or
- Requires the writebackup.vim plugin (vimscript #1828), version 1.30 or
- The writebackupVersionControl.vim plugin (vimscript #1829), which
  complements writebackup.vim, fully supports this extension, but is not

For a permanent configuration, put the following commands into your vimrc:

To change the name of the adjacent backup directory, specify a different
template via
    let g:WriteBackupAdjacentDir_BackupDirTemplate = '%s.backup'
This must contain the "%s" placeholder, which is replaced with the original
file's directory, e.g. "backup of %s".

This plugin injects itself into writebackup.vim via the
g:WriteBackup_BackupDir configuration. Its previous value is saved in
g:WriteBackupAdjacentDir_BackupDir and used as a fallback, when no adjacent
directory exists. If you need to change the fallback after sourcing the
plugins, use the latter variable. However, to override this for a particular
buffer, you still have to use the b:WriteBackup_BackupDir variable, as this
plugin does not provide yet another override.

By default, the plugin also searches for backup directories in upper
directories (until it reaches the file system root), and then re-creates the
path to the current file inside that parallel backup directory hierarchy. If
you want to revert to the version 1.x behavior of the plugin, turn this off
    let g:WriteBackupAdjacentDir_IsUpwardsBackupDirSearch = 0

Rating scripts is only available on the HTTPS page

script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
writebackupToAdjacentDir-2.01.vmb.gz 2.01 2014-01-29 7.0 Ingo Karkat - Compatibility: Fix Funcref errors for Vim 7.0/1.
writebackupToAdjacentDir-2.00.vmb.gz 2.00 2013-08-02 7.0 Ingo Karkat - ENH: Implement upwards directory hierarchy search for backup directories, and then re-create the path to the current file inside that parallel backup directory hierarchy.
- ENH: :WriteBackupMakeAdjacentDir now optionally also takes a target directory to better support the new upwards directory hierarchy search.
- Abort :WriteBackupMakeAdjacentDir on error.
- Add dependency to ingo-library (vimscript #4433). *** You need to separately install ingo-library (vimscript #4433) version 1.011 (or higher)! ***
writebackupToAdjacentDir.vba.gz 1.10 2012-02-17 7.0 Ingo Karkat ENH: Save configured g:WriteBackup_BackupDir and use that as a fallback instead of always defaulting to '.', thereby allowing absolute and dynamic backup directories as a fallback. Suggested by Geoffrey Nimal.
writebackupToAdjacentDir.vba.gz 1.00 2010-06-02 7.0 Ingo Karkat Initial upload
ip used for rating:

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.
SourceForge.net Logo