Use persistent undo with vim.

Vim will now keep 10000 undo steps for each file in ~/.vim/tmp/undo that will be reloaded upon opening that file.