I want to create a backup of the file I'm editing before each write. For example, if I am editing some file.txt
, when I go to write the file with :w
, I want vim to first save a backup of file.txt
within a directory (i.e. ~/.vim_backups/
) as file_2013-01-01_01-01-01.txt
, where this represents YYYY-MM-DD_HH-MM-SS.txt
. I am aware of alternatives such as version control, but I'm curious if this is possible in vim.
Vim – Store a backup before each write
vimvimrc
Best Answer
This vim wikia article titled: Keep incremental backups of edited files, sounds like what you're looking for. There's this method which attaches a save routine so that it's mapped to the Esc key.
There are several other methods discussed in the Wiki topic.