diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2017-11-02 14:30:02 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2017-11-02 14:30:02 +1300 |
commit | d3fe457b0ea8400e79bcd54c6c803870921d1b9e (patch) | |
tree | 52e9f6e6b3dc1ebd624ee2249b4ea01dcfd8ffae | |
parent | Merge branch 'feature/options-audit' into develop (diff) | |
parent | Have bigfileturn local syntax off (configurably) (diff) | |
download | dotfiles-d3fe457b0ea8400e79bcd54c6c803870921d1b9e.tar.gz dotfiles-d3fe457b0ea8400e79bcd54c6c803870921d1b9e.zip |
Merge branch 'feature/vim-plugin' into develop
* feature/vim-plugin:
Have bigfileturn local syntax off (configurably)
Make bigfile 'synmaxcol' setting configurable
Refactor plugin function for dependency injection
Rename variable and autocmd to use plugin prefix
Make bigfile size variable an option with default
Expand comment header for bigfile.vim
Move Vim big file options config into plugin
-rw-r--r-- | Makefile | 12 | ||||
-rw-r--r-- | vim/config/bigfile.vim | 28 | ||||
-rw-r--r-- | vim/doc/bigfile.txt | 12 | ||||
-rw-r--r-- | vim/plugin/bigfile.vim | 60 |
4 files changed, 83 insertions, 29 deletions
@@ -474,9 +474,11 @@ install-urxvt: urxvt/ext/select install-vim: install-vim-after \ install-vim-bundle \ install-vim-config \ + install-vim-doc \ install-vim-ftdetect \ install-vim-ftplugin \ - install-vim-indent + install-vim-indent \ + install-vim-plugin install-vim-after: find vim/after -name .git -prune -o \ @@ -493,6 +495,10 @@ install-vim-config: cp -p -- vim/vimrc $(HOME)/.vimrc cp -p -- vim/config/*.vim $(HOME)/.vim/config +install-vim-doc: + mkdir -p -- $(HOME)/.vim/doc + cp -p -- vim/doc/*.txt $(HOME)/.vim/doc + install-vim-ftdetect: mkdir -p -- $(HOME)/.vim/ftdetect cp -p -- vim/ftdetect/*.vim $(HOME)/.vim/ftdetect @@ -505,6 +511,10 @@ install-vim-indent: mkdir -p -- $(HOME)/.vim/indent cp -p -- vim/indent/*.vim $(HOME)/.vim/indent +install-vim-plugin: + mkdir -p -- $(HOME)/.vim/plugin + cp -p -- vim/plugin/*.vim $(HOME)/.vim/plugin + install-vim-gui: install-vim \ install-vim-gui-config diff --git a/vim/config/bigfile.vim b/vim/config/bigfile.vim deleted file mode 100644 index 5c68b1a7..00000000 --- a/vim/config/bigfile.vim +++ /dev/null @@ -1,28 +0,0 @@ -" When opening a large file, take some measures to keep things loading quickly -if has('eval') && has('autocmd') - - " Threshold is 10 MiB - let g:big_file_size = 10 * 1024 * 1024 - - " Declare function for turning off slow options - function! s:BigFileMeasures() - let l:file = expand('<afile>') - if getfsize(l:file) > g:big_file_size - 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 dotfiles_big_file_measures - autocmd! - autocmd BufReadPre * call s:BigFileMeasures() - augroup end -endif diff --git a/vim/doc/bigfile.txt b/vim/doc/bigfile.txt new file mode 100644 index 00000000..d7e56f28 --- /dev/null +++ b/vim/doc/bigfile.txt @@ -0,0 +1,12 @@ +*bigfile.txt* Disable slow options for big files to speed things up + +Author: Tom Ryder <tom@sanctum.geek.nz> +License: Same terms as Vim itself (see |license|) + +This plugin adds an |autocmd| hook to check the file size of an incoming +buffer, and if it's over a certain threshold, disables certain options in order +to make the file a bit easier to edit. + +This plugin lives in Tom Ryder's "dotfiles" suite, and will eventually be spun +off into a separate distribution as it solidifies and this documentation +improves. diff --git a/vim/plugin/bigfile.vim b/vim/plugin/bigfile.vim new file mode 100644 index 00000000..fece3d9b --- /dev/null +++ b/vim/plugin/bigfile.vim @@ -0,0 +1,60 @@ +" +" bigfile.vim: When opening a large file, take some measures to keep things +" loading quickly. +" +" Author: Tom Ryder <tom@sanctum.geek.nz> +" Copyright: 2017 +" License: Same as Vim itself +" +if has('eval') && has('autocmd') + + " Default threshold is 10 MiB + if !exists('g:bigfile_size') + let g:bigfile_size = 10 * 1024 * 1024 + endif + + " Default to leaving syntax highlighting off + if !exists('g:bigfile_syntax') + let g:bigfile_syntax = 0 + endif + + " Cut 'synmaxcol' down to this or smaller for big files + if !exists('g:bigfile_size_synmaxcol') + let g:bigfile_size_synmaxcol = 256 + endif + + " Declare function for turning off slow options + function! s:BigFileOptions(name, size) + + " Don't do anything if the file is under the threshold + if getfsize(a:name) <= a:size + return + endif + + " Turn off backups, swap files, and undo files + setlocal nobackup + setlocal nowritebackup + setlocal noswapfile + if has('persistent_undo') + setlocal noundofile + endif + + " Limit the number of columns of syntax highlighting + if exists('&synmaxcol') && &synmaxcol > g:bigfile_size_synmaxcol + execute 'setlocal synmaxcol=' . g:bigfile_size_synmaxcol + endif + + " Disable syntax highlighting if configured to do so + if !g:bigfile_syntax + setlocal syntax=OFF + endif + + endfunction + + " Define autocmd for calling to check filesize + augroup bigfile_options_bufreadpre + autocmd! + autocmd BufReadPre * call s:BigFileOptions(expand('<afile>'), g:bigfile_size) + augroup end + +endif |