Just another tech blog.

A blog abt GNU/Linux, programming, hacking, and my life.

Taking backup of files using Vim

Posted by ajay on June 1, 2006

Many people have the habit of saving the file after every around 5 minutes .. there might be cases when you want to change something in your programme and see the output .. and if the output is not worth .. you might want to get the original programme back .. or by mistake you delete some lines frm a file and save the file In both cases you need the original file back .. To escape from such situation .. you might move the file to another file each time you want to edit the file but that is very tedious work .. so here is another method .. set the backup option in vim and it will do the rest for you ..

wat you have to do is ..

[x@localhost.localadmin]vim ~/.vimrc

now append these lines ..

set bk

set bdir=~/backup

set bex=bkp

now save the file .. in these lines .. first lines specifies that the user wants to take backup .. ( enables the backup option .. ) . The second line specifies the directory in which the backup will be stored .. the line specifies the string to be appended to the file name to get the name of the backup file .. like you save a file named a.cpp then a file named a.cppbkp will be created in ~/backup directory .. you can skip the third line .. in that case the default string which will be backup files contain is ~ .. ( the example file be stored as a.cpp~ ) ..

From now onwards whenever you save any file its backup will be saved in ~/backup directory .. ( you might choose a different one based on your choice .. ) .. and remember before opening any file CREATE a DIRECTORY NAMED BACKUP in your HOME DIRECTORY .. and the backup system is ready .. and whenever you save a file second time .. the original backup file is rewritten .. I still dont the know the methods for multilevel backup .. if you know .. please let me know by leaving a comment ..

Advertisements

2 Responses to “Taking backup of files using Vim”

  1. Turbo said

    This is a nice option. Vim keeps surprising me!!

  2. Jane Goody said

    My fellow on Orkut shared this link and I’m not dissapointed that I came to your blog.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: