Handy vim tip


I’ve been working on a number of bits of code recently, and have found that it’s not entirely practical to check into RCS or SVN for every change that I’ve made. I really like to work by committing when I’ve finished adding a feature to a script, or a project. Hence, I’ve been using the vim “set backup” option. However, this has some limitations, and hence I decided to have a look at what .vimrc could do for me.

  set backupdir=~/.vimbackup/
  let d = strftime("-%d%m%y-%H%M")
  let d = "set backupext=".d
  execute d
  set backup            

Now I have backup files in ~/.vimbackup/ that reflect the time I started editing the file. This is quite handy if you, like me, :wq! and execute when testing. I’ll probably need to write a script to cleanup ~/.vimbackup at some point though!