Skip to content

Instantly share code, notes, and snippets.

@kaero
Created July 23, 2015 10:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaero/7377359b104cb4d029d3 to your computer and use it in GitHub Desktop.
Save kaero/7377359b104cb4d029d3 to your computer and use it in GitHub Desktop.
" dont backup anything if vim launched with root priveleges
if $USER != 'root'
" create and set backup, swap and undo directories
let s:tmp_path = '/tmp/vim_temp/' . $USER . '/'
if ! filewritable(s:tmp_path)
silent execute '!mkdir -p "' . s:tmp_path . '"'
else
" remove backups older than 8 days (-ctime +8)
silent execute '!find "' . s:tmp_path . '" -type f -ctime +8 -delete'
endif
au BufWritePre * let &bex = '-' . strftime("%Y.%m.%dT%H:%M:%S") . '~'
" double slash in the end of path used to avoid conflicts
" between files with equal names (swap and undo files names will contains full path to the file)
let &directory = s:tmp_path . '/'
let &backupdir = s:tmp_path
set backup
let &undodir = s:tmp_path . '/'
set udf
endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment