If the 'patchmode' option is non-empty, then whenever a file
is saved, a version of the previously saved version is kept,
but renamed to {file}.{number}.{patchext}, where:
{file} is the filename of the file being saved
{number} is a number between 0001 and 9999
{patchext} is the value of the 'patchmode' option.

Optionally, the saved versions can be placed in a subdirectory.

Note that this plugin is DISABLED if 'patchmode' is empty.
Also, this plugin won't work if 'backupdir' is empty or if
'backup' is unset, so to get started, put the following in
your ".vimrc"

set backup
set patchmode=.clean

So, for example, if 'patchmode' is '.clean' and we save a
file named "test.txt" we'll have the following files:

COMMANDS:
:Purge [-a] [-v] [N]
Removes all but the patchmode files numbered N and below.
The [N] is optional, and defaults to 1.
Normally, this operates only on the patchmode files associated
with the current buffer, but if the [-a] flag is given, then
it operates on all patchmode files in the directory of the
current file.
If the optional [-v] (verbose) flag is given, then the filename
of each deleted patchmode file is printed.

Use ":Purge 0" to delete all of the patchmode files for the
current file.

Use ":Purge -a 0" to delete all of the patchmode files in
the directory of the current file.

:VersDiff [arg]
Does a "diffsplit" on the current file with the version
indicated by [arg]. So, for example, if the current
file is "test.txt" then the ":VersDiff 5" command will
do a "diffsplit" with "test.txt.0005.clean", assuming
&patchmode is ".clean"

If [arg] is zero (the default), then the diff is done with
the current saved version of the file.

If [arg] is negative, then the diff is done with the
[arg]th oldest file; e.g., if [arg] is "-5" and there are
versions 0001-0023 saved on disk, then the version that
is diffed will be (23-5+1)=19, i.e, "test.txt.0019" will
be diffed.

If [arg] is "-cvs", then the diff is done with the most recently
checked-in version of the file.

If [arg] is "-", then the current VersDiff window is decremented.
If [arg] is "+", then the current VersDiff window is incremented.
(Note that if VersDiff is currently doing a cvs diff, then
the cvs revision is incremented/decremented)

If [arg] is "-c", then any current VersDiff window is closed.

HINTS:
If you use GNU 'ls', then try adding "-I'*.clean'" (without the
double quotes) to your 'ls' alias (assuming &patchmode==.clean)

It's also helpful to have the patchmode value in the backupskip,
suffixes, and wildignore vim options:

Save the plugin as $VIMRUNTIME/plugin/savevers.vim
and you're good to go. The default settings should
work fine for most people, but to enable it, the following
settings (put in .vimrc) should get you started:

set backup
set patchmode=.clean

This plugin can be configured by setting the following
variables in ".vimrc"

savevers_types - This is a comma-separated list of filename
patterns. Sets the types of files that
will have numbered versions.
Defaults to "*" (all files).

savevers_dirs - This is a comma-separated list of directories
that will be tried to store the patchmode files.
The first writable directory in this list is used.
This works much like the vim 'backupdir' option.
To set this to the same as 'backupdir', do
:let savevers_dirs = &backupdir
Defaults to '.', which puts all patchmode files
in the same directory as the original file.

versdiff_no_resize - Disables window resizing during ":VersDiff"

versdiff_max_cols - Limits window resizing during ":VersDiff"

So, for example, if the user has in ~/.vimrc:
let savevers_types = "*.c,*.h,*.vim"
let savevers_max = 99
let savevers_purge = 0
then only "*.c", "*.h", and "*.vim" files will be numbered,
and there will be a maximum of 99 versions saved.
Also, the ":Purge" command will purge all numbered versions
(instead of the default, which is to delete all but the oldest).