sponsor Vim development Vim logo Vim Book Ad

savevers.vim : Automatically save and diff multiple, sequentially numbered revisions (like VMS)

 script karma  Rating 213/80, Downloaded by 6283  Comments, bugs, improvements  Vim wiki

created by
Ed Ralston
script type
Automatically saves and compares multiple, sequentially numbered
old revisions of files (like in VMS)

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:

-rw-r----- 1 eralston admin  106 Sep 20 11:14 test.txt
-rw-r----- 1 eralston admin  102 Sep 20 11:12 test.txt.0001.clean

If we make subsequent changes to "test.txt" and save it a
few more times, we'll end up with something like:

-rw-r----- 1 eralston admin  226 Sep 20 11:43 test.txt
-rw-r----- 1 eralston admin  102 Sep 20 11:12 test.txt.0001.clean
-rw-r----- 1 eralston admin  106 Sep 20 11:14 test.txt.0002.clean
-rw-r----- 1 eralston admin  132 Sep 20 11:22 test.txt.0003.clean
-rw-r----- 1 eralston admin  148 Sep 20 11:34 test.txt.0004.clean

   :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.

   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:

      :exe "set backupskip+=*" . &patchmode
      :exe "set suffixes+=" . &patchmode
      :exe "set wildignore+=*" . &patchmode

   Also, here are some nice mappings that allow quick comparison
   of the current file with previous versions.  Pressing <F5>
   successively shows the diff with older versions.

      " <F5> decrease version viewed in VersDiff window
      " <F6> increase version viewed in VersDiff window
      " <F7> do VersDiff with cvs version of current file
      " <F8> cancel VersDiff window
      nmap <silent> <F5> :VersDiff -<cr>
      nmap <silent> <F6> :VersDiff +<cr>
      nmap <silent> <F7> :VersDiff -cvs<cr>
      nmap <silent> <F8> :VersDiff -c<cr>
install details
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_max       - Sets the maximum patchmode version.
                        Defaults to "9999".

   savevers_purge     - Sets default value of [N] for the :Purge command
                        Defaults to "1".

   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).

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
savevers.vim 0.8 2001-10-10 6.0 Ed Ralston Corrected some obscure documentation.  Allow cvs revisions to be incremented/decremented.
savevers.vim 0.7 2001-10-02 6.0 Ed Ralston Added option to specify directory for patchmode files
savevers.vim 0.6 2001-10-01 6.0 Ed Ralston ":VersDiff" command improvements
savevers.vim 0.5 2001-10-01 6.0 Ed Ralston Added ":VersDiff" command.
savevers.vim 0.4 2001-09-26 6.0 Ed Ralston Added "-a" and "-v" flags to the ":Purge" command.
savevers.vim 0.3 2001-09-25 6.0 Ed Ralston Added configuration options
savevers.vim 0.2 2001-09-25 6.0 Ed Ralston allow up to 9999 numbered versions
savevers.vim 0.1 2001-09-20 6.0 Ed Ralston 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.