Monday, January 28, 2008

Back It Up

This has saved my ass enough times that I feel compelled to mention it.

You can have Vim make a backup copy of any file you save right before overwriting it by adding the following to your .vimrc.

set backup " enable backups
set backupdir=/your/homedir/.vim/backup " where to put backup file

I set my tempfile directory for good measure.

set directory=/your/homedir/.vim/temp " new temp dir

Note: you will need to create the directories inside .vim before this will work.

Using Perl

If your install of Vim was built with an embedded Perl interpreter, you can leverage the power of the language to your advantage. I typically use the embedded Perl interpreter to add the power of Perl's regular expressions to Vim. Say you're editing a file, you make a selection in visual mode, and you want to substitute all digits with the `x' character. This is easily accomplished using the perldo ex command.

:perldo s/\d/x/g

See and :help perldo for more information.