aboutsummaryrefslogtreecommitdiff
path: root/plugin/big_file_options.vim
blob: 9b60976a572c49042de1a972a31ad17023e80863 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"
" 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') || v:version < 600
  finish
endif
let g:loaded_big_file_options = 1

" Declare function for turning off slow options
function! s:BigFileOptions()

  " Don't do anything if the buffer size is under the threshold
  let l:size = exists('g:big_file_size')
        \ ? g:big_file_size
        \ : 10 * 1024 * 1024
  if line2byte(line('$') + 1) <= l: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
  let l:synmaxcol = exists('g:big_file_synmaxcol')
        \ ? g:big_file_synmaxcol
        \ : 256
  if exists('+synmaxcol') && &l:synmaxcol > l:synmaxcol
    let &l:synmaxcol = l:synmaxcol
  endif

  " Disable syntax highlighting if configured to do so
  let l:syntax = exists('g:big_file_syntax')
        \ ? g:big_file_syntax
        \ : 0
  if !l:syntax
    setlocal syntax=OFF
  endif

endfunction

" Define autocmd for calling to check filesize
augroup big_file_options
  autocmd!
  autocmd BufReadPost * call s:BigFileOptions()
augroup end