aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2018-05-31 17:41:20 +1200
committerTom Ryder <tom@sanctum.geek.nz>2018-05-31 17:41:20 +1200
commite70de13287c7a7a0a408075b7954e9d14ed606bf (patch)
tree57ce6249662e98fac91129d01b9a6322b28040b2
downloadvim-big-file-options-0.1.0.tar.gz (sig)
vim-big-file-options-0.1.0.zip
Initial commitv0.1.0
Copied with minimal changes from tejr's dotfiles suite, v0.36.0.
-rw-r--r--README.markdown15
-rw-r--r--doc/big_file_options.txt49
-rw-r--r--plugin/big_file_options.vim66
3 files changed, 130 insertions, 0 deletions
diff --git a/README.markdown b/README.markdown
new file mode 100644
index 0000000..0bb2cba
--- /dev/null
+++ b/README.markdown
@@ -0,0 +1,15 @@
+big\_file\_options.vim
+======================
+
+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. It disables backups, swap files, undo
+files, and by default syntax highlighting.
+
+License
+-------
+
+Copyright (c) [Tom Ryder][1]. Distributed under the same terms as Vim itself.
+See `:help license`.
+
+[1]: https://sanctum.geek.nz/
diff --git a/doc/big_file_options.txt b/doc/big_file_options.txt
new file mode 100644
index 0000000..a4ec5bb
--- /dev/null
+++ b/doc/big_file_options.txt
@@ -0,0 +1,49 @@
+*big_file_options.txt* For Vim version 7.0 Last change: 2018 May 31
+
+DESCRIPTION *big_file_options*
+
+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. It disables backups, swap files,
+undo files, and by default syntax highlighting.
+
+It's similar to the much older and more sophisticated LargeFile plugin by
+Charles Campbell, which is based on VimTip #611:
+<http://vim.wikia.com/wiki/Faster_loading_of_large_files>
+
+If you want more options and bells and whistles, you should definitely use
+that instead. I'm intentionally keeping this very small and simple; it should
+be install-and-forget.
+
+REQUIREMENTS *big_file_options-requirements*
+
+This plugin is only available if 'compatible' is not set. It also requires the
+|+autocmd| feature.
+
+OPTIONS *big_file_options-options*
+
+There are a few options you can set in your |vimrc| before loading the plugin:
+
+ *g:big_file_size*
+Set `g:big_file_size` to the threshold in bytes beyond which a file should be
+considered "big"; this defaults to 10 MiB.
+
+ *g:big_file_syntax*
+Set `g:big_file_syntax` to either 1 or 0 depending on whether you want to
+disable syntax highlighting completely on large files.
+
+ *g:big_file_synmaxcol*
+Set `g:big_file_synmaxcol` to the number of columns for which syntax
+highlighting should be done on big files, assuming |g:big_file_syntax| is
+enabled. It defaults to 256 and only works if you have the |+synmaxcol|
+feature.
+
+AUTHOR *big_file_options-author*
+
+Written and maintained by Tom Ryder <tom@sanctum.geek.nz>.
+
+LICENSE *big_file_options-license*
+
+Licensed for distribution under the same terms as Vim itself (see |license|).
+
+ vim:tw=78:ts=8:ft=help:norl:
diff --git a/plugin/big_file_options.vim b/plugin/big_file_options.vim
new file mode 100644
index 0000000..f7fa028
--- /dev/null
+++ b/plugin/big_file_options.vim
@@ -0,0 +1,66 @@
+"
+" big_file_options.vim: When opening a large file, take some measures to keep
+" things loading quickly.
+"
+" Author: Tom Ryder <tom@sanctum.geek.nz>
+" License: Same as Vim itself
+"
+if exists('g:loaded_big_file_options') || &compatible
+ finish
+endif
+if !has('autocmd')
+ finish
+endif
+let g:loaded_big_file_options = 1
+
+" Default threshold is 10 MiB
+if !exists('g:big_file_size')
+ let g:big_file_size = 10 * 1024 * 1024
+endif
+
+" Default to leaving syntax highlighting off
+if !exists('g:big_file_syntax')
+ let g:big_file_syntax = 0
+endif
+
+" Cut 'synmaxcol' down to this or smaller for big files
+if !exists('g:big_file_synmaxcol')
+ let g:big_file_synmaxcol = 256
+endif
+
+" Declare function for turning off slow options
+function! s:BigFileOptions()
+
+ " Don't do anything if the buffer size is under the threshold
+ if line2byte(line('$') + 1) <= g:big_file_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:big_file_synmaxcol
+ execute 'setlocal synmaxcol=' . g:big_file_synmaxcol
+ endif
+
+ " Disable syntax highlighting if configured to do so
+ if !g:big_file_syntax
+ setlocal syntax=OFF
+ endif
+
+endfunction
+
+" Define autocmd for calling to check filesize
+augroup big_file_options_bufreadpost
+ autocmd!
+ autocmd BufReadPost
+ \ *
+ \ call s:BigFileOptions()
+augroup end