aboutsummaryrefslogtreecommitdiff
path: root/vim/plugin/bigfile.vim
blob: d1d9ca61885eac79eb1a3d8b8a10349d2c6fab3f (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
"
" 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')

  " 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