diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2017-10-28 21:32:29 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2017-10-28 21:32:37 +1300 |
commit | cf8d82653ae77b9927f18b24ac35f6b099da7c49 (patch) | |
tree | c41f65fdd51821a39f481605f7c8b70c439c3d78 /vim | |
parent | Add ! to runtime for sourcing vimrc subfiles (diff) | |
download | dotfiles-cf8d82653ae77b9927f18b24ac35f6b099da7c49.tar.gz dotfiles-cf8d82653ae77b9927f18b24ac35f6b099da7c49.zip |
Move swapfile .vimrc config into subfile
Diffstat (limited to 'vim')
-rw-r--r-- | vim/config/swapfile.vim | 32 | ||||
-rw-r--r-- | vim/vimrc | 33 |
2 files changed, 32 insertions, 33 deletions
diff --git a/vim/config/swapfile.vim b/vim/config/swapfile.vim new file mode 100644 index 00000000..39e1ab95 --- /dev/null +++ b/vim/config/swapfile.vim @@ -0,0 +1,32 @@ +" 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 swapskip + autocmd! + silent! autocmd BufNewFile,BufReadPre + \ /tmp/*,$TMPDIR/*,$TMP/*,$TEMP/*,*/shm/* + \ setlocal noswapfile + augroup END + endif + +" Otherwise, don't use swap files at all +else + set noswapfile +endif @@ -268,39 +268,6 @@ endif nnoremap & :&&<CR> vnoremap & :&&<CR> -" 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 swapskip - autocmd! - silent! autocmd BufNewFile,BufReadPre - \ /tmp/*,$TMPDIR/*,$TMP/*,$TEMP/*,*/shm/* - \ setlocal noswapfile - augroup END - endif - -" Otherwise, don't use swap files at all -else - set noswapfile -endif - " Don't bother about checking whether Escape is being used as a means to enter " a Meta-key combination, just register Escape immediately set noesckeys |