Saving backup files automatically in (g)Vim after saving a file

6

1

I had a problem with my gVim. I lost some important modifications after I plugged on my machine after a hibernating process.

To avoid this kind of problem, I would like to know if it's possible to add something in my .vimrc (or a plugin) that automatically backups all saving made to my files. Disk space is not an issue, I can delete these files after.

I'm already using

set backup
set backupdir=~/.backup/vim
set directory=~/.swap/vim

This creates a myfile.extension~ in my .backup/vim.

...but I would like this configuration to add ~ to first save, ~0 to second, ~1 to third, ~2 to fourth, and so on - something that keeps copies from all modifications I made to a file.

Is this possible? Do you know if there's a plugin for this?

Somebody still uses you MS-DOS

Posted 2010-06-04T13:44:34.977

Reputation: 4 143

Not this way but you could symlink the config into Dropbox which supports rollback. However, MSDOS is not a supported for Dropbox. :) – Apache – 2010-06-04T13:46:32.400

Haha, good one! It's indeed an interesting approach (Dropbox), but I can't have Dropbox installed on my work machine. :( – Somebody still uses you MS-DOS – 2010-06-04T14:23:43.850

Using NTFS's shadow copy? Or some app which monitors for changes and do the job ? (sorry for no 100% answer. :)) – Apache – 2010-06-04T17:13:19.093

I would like to have a Vim solution instead of a monitoring solution... The simpler solution I can think of is creating a script that before saving, checks files with the same names and append a number sequence to it. But since I have no experience in vim scritps, it would be difficult to me implement. – Somebody still uses you MS-DOS – 2010-06-04T19:51:14.380

Answers

1

Simple solution: set your backup drive as a Dropbox folder. It keeps revisions of all your saved files, and you don't need to setup anything.

Another solution: http://vim.wikia.com/wiki/VimTip962

Somebody still uses you MS-DOS

Posted 2010-06-04T13:44:34.977

Reputation: 4 143

2

Use RCS to keep a backup version whenever you save a file : rcsvers.vim http://www.vim.org/scripts/script.php?script_id=563

rpilkey

Posted 2010-06-04T13:44:34.977

Reputation: 346

1

Automatically save and diff multiple, sequentially numbered revisions (like VMS) : savevers.vim http://www.vim.org/scripts/script.php?script_id=89

rpilkey

Posted 2010-06-04T13:44:34.977

Reputation: 346

0

Well this should be easy if you set a git repo in your backuping folder. and add vim settings which triggers the following script on each save

cd ~/.backup/vim
git add .
git commit -m "incremental commit"

gr4viton

Posted 2010-06-04T13:44:34.977

Reputation: 1