From 0dbc9b35f9ae0c21390f2133406da3279af190c7 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 28 Oct 2017 21:53:46 +1300 Subject: Move BigFileMeasures() .vimrc func into subfile Also add a note to IDEAS.md for later to consider packaging this as a proepr plugin, even if it doesn't actually leave the dotfiles repository just yet. --- IDEAS.md | 2 ++ vim/config/bigfile.vim | 28 ++++++++++++++++++++++++++++ vim/vimrc | 29 ----------------------------- 3 files changed, 30 insertions(+), 29 deletions(-) create mode 100644 vim/config/bigfile.vim diff --git a/IDEAS.md b/IDEAS.md index bba9e314..0a812167 100644 --- a/IDEAS.md +++ b/IDEAS.md @@ -19,3 +19,5 @@ Ideas * I can probably get rid of all that nasty templated shell by writing something that wraps around td(1df) and generates shell script to run, and calls that via `eval`. +* The BigFileMeasures() function in .vim/config/bigfile.vim should maybe be a + self-contained plugin rather than a config subfile. diff --git a/vim/config/bigfile.vim b/vim/config/bigfile.vim new file mode 100644 index 00000000..f15c7e85 --- /dev/null +++ b/vim/config/bigfile.vim @@ -0,0 +1,28 @@ +" When opening a large file, take some measures to keep things loading quickly +if has('eval') && has('autocmd') + + " Threshold is 10 MiB + let g:bigfilesize = 10 * 1024 * 1024 + + " Declare function for turning off slow options + function! BigFileMeasures() + let l:file = expand('') + if getfsize(l:file) > g:bigfilesize + setlocal nobackup + setlocal nowritebackup + setlocal noswapfile + if has('persistent_undo') + setlocal noundofile + endif + if exists('&synmaxcol') + setlocal synmaxcol=256 + endif + endif + endfunction + + " Define autocmd for calling to check filesize + augroup bigfilesize + autocmd! + autocmd BufReadPre * call BigFileMeasures() + augroup end +endif diff --git a/vim/vimrc b/vim/vimrc index d00376f0..9dcbb38f 100644 --- a/vim/vimrc +++ b/vim/vimrc @@ -249,32 +249,3 @@ if has('autocmd') autocmd! augroup END endif - -" When opening a large file, take some measures to keep things loading quickly -if has('eval') && has('autocmd') - - " Threshold is 10 MiB - let g:bigfilesize = 10 * 1024 * 1024 - - " Declare function for turning off slow options - function! BigFileMeasures() - let l:file = expand('') - if getfsize(l:file) > g:bigfilesize - setlocal nobackup - setlocal nowritebackup - setlocal noswapfile - if has('persistent_undo') - setlocal noundofile - endif - if exists('&synmaxcol') - setlocal synmaxcol=256 - endif - endif - endfunction - - " Define autocmd for calling to check filesize - augroup bigfilesize - autocmd! - autocmd BufReadPre * call BigFileMeasures() - augroup end -endif -- cgit v1.2.3