diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2017-11-10 21:13:21 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2017-11-10 21:13:21 +1300 |
commit | 69cac9e123d74fa9fecf96177cb79d8370a833f1 (patch) | |
tree | 013a570c94edc08d1153ef30f7043d503ce529a5 /vim/config | |
parent | Merge join,indent.vim into whitespace.vim (diff) | |
download | dotfiles-69cac9e123d74fa9fecf96177cb79d8370a833f1.tar.gz dotfiles-69cac9e123d74fa9fecf96177cb79d8370a833f1.zip |
Move backup, swap, and undo dir logic into plugins
Diffstat (limited to 'vim/config')
-rw-r--r-- | vim/config/backup.vim | 33 | ||||
-rw-r--r-- | vim/config/swapfile.vim | 44 | ||||
-rw-r--r-- | vim/config/undo.vim | 22 |
3 files changed, 28 insertions, 71 deletions
diff --git a/vim/config/backup.vim b/vim/config/backup.vim index 718647fc..8735a094 100644 --- a/vim/config/backup.vim +++ b/vim/config/backup.vim @@ -1,26 +1,11 @@ -" Use backup features if on a UNIX-like system and not using sudo(8) -if !strlen($SUDO_USER) && has('unix') +" Default to no backup files at all, in a way that even ancient/tiny Vims will +" understand; the auto_backupdir.vim plugin will take care of re-enabling this +set nobackup +set nowritebackup - " Keep backups with a .bak extension in ~/.vim/backup; the double-slash at - " the end of the directory is supposed to prod Vim into keeping the full - " path to the file in its backup filename to avoid collisions, but I don't - " think it actually works for backups, just undo and swap files - set backup - set backupext=.bak - set backupdir^=~/.vim/backup// +" If backps are enabled, use a more explicit and familiar backup suffix +set backupext=.bak - " This option already includes various temporary directories, but we - " append to it so that we don't back up anything in a shared memory - " filesystem either - set backupskip+=*/shm/* - - " Create the backup directory if necessary and possible - if !isdirectory($HOME . '/.vim/backup') && exists('*mkdir') - call mkdir($HOME . '/.vim/backup', 'p', 0700) - endif - -" Don't use backups at all otherwise -else - set nobackup - set nowritebackup -endif +" Don't back up files in anything named */shm/; they might be password +" files +set backupskip+=*/shm/* diff --git a/vim/config/swapfile.vim b/vim/config/swapfile.vim index 778ae2f0..bf91aa6b 100644 --- a/vim/config/swapfile.vim +++ b/vim/config/swapfile.vim @@ -1,32 +1,14 @@ -" Swap files are used if using Unix and not using sudo(8); I very seldom need -" them, but they are occasionally useful after a crash, and they don't really -" get in the way if kept in their own directory -if !strlen($SUDO_USER) && has('unix') - - " Use swap files but keep them in ~/.vim/swap; the double-slash at the end - " of the directory prods Vim into keeping the full path to the file in its - " undo filename to avoid collisions; the same thing works for undo files - set swapfile - set directory^=~/.vim/swap// - - " Create the ~/.vim/swap directory if necessary and possible - if !isdirectory($HOME . '/.vim/swap') && exists('*mkdir') - call mkdir($HOME . '/.vim/swap', 'p', 0700) - endif - - " Don't keep swap files for files in temporary directories or shared memory - " filesystems; this is because they're used as scratch spaces for tools - " like sudoedit(8) and pass(1) and hence could present a security problem - if has('autocmd') - augroup dotfiles_swap_skip - autocmd! - autocmd BufNewFile,BufReadPre - \ /tmp/*,$TMPDIR/*,$TMP/*,$TEMP/*,*/shm/* - \ setlocal noswapfile - augroup END - endif - -" Otherwise, don't use swap files at all -else - set noswapfile +" Default to no swapfile files at all, in a way that even ancient/tiny Vims +" will understand; the auto_swapdir.vim plugin will take care of this +set noswapfile + +" Don't keep swap files from temporary directories or shared memory in case +" they're secrets +if has('autocmd') + augroup dotfiles_swap_skip + autocmd! + autocmd BufNewFile,BufReadPre + \ /tmp/*,$TMPDIR/*,$TMP/*,$TEMP/*,*/shm/* + \ setlocal noswapfile + augroup END endif diff --git a/vim/config/undo.vim b/vim/config/undo.vim index c9539665..c31780e7 100644 --- a/vim/config/undo.vim +++ b/vim/config/undo.vim @@ -4,23 +4,13 @@ inoremap <C-c> <C-c>u " Keep screeds of undo history set undolevels=2000 -" Keep undo history in a separate file if the feature is available, we're on -" Unix, and not using sudo(8); this goes really well with undo visualization -" plugins like Gundo or Undotree. -if !strlen($SUDO_USER) && has('unix') && has('persistent_undo') +" 'undodir' and 'undofile' settings will be taken care of by the +" auto_undodir.vim plugin if applicable/possible +if has('persistent_undo') + set noundofile - " Keep per-file undo history in ~/.vim/undo; the double-slash at the end - " of the directory prods Vim into keeping the full path to the file in its - " undo filename to avoid collisions; the same thing works for swap files - set undofile - set undodir^=~/.vim/undo// - - " Create the ~/.vim/undo directory if necessary and possible - if !isdirectory($HOME . '/.vim/undo') && exists('*mkdir') - call mkdir($HOME . '/.vim/undo', 'p', 0700) - endif - - " Don't track changes to sensitive files + " Don't keep undo files from temporary directories or shared memory in case + " they're secrets if has('autocmd') augroup dotfiles_undo_skip autocmd! |