diff options
| author | jdhao <jdhao@hotmail.com> | 2022-08-15 00:06:52 +0800 |
|---|---|---|
| committer | jdhao <jdhao@hotmail.com> | 2022-08-15 00:06:52 +0800 |
| commit | e7e4892c22c6973b25083d9654a778cf79cd3cb9 (patch) | |
| tree | 137865974193a012c5d750faf9dbbee50ac7e2f9 /core | |
| parent | a52a362b028d83a349a311e80bb4c29fe06b0849 (diff) | |
handle large file better
Diffstat (limited to 'core')
| -rw-r--r-- | core/autocommands.vim | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/core/autocommands.vim b/core/autocommands.vim index c055c49..70b40db 100644 --- a/core/autocommands.vim +++ b/core/autocommands.vim @@ -135,3 +135,23 @@ augroup auto_create_dir autocmd! autocmd BufWritePre * lua require('utils').may_create_dir() augroup END + +" ref: https://vi.stackexchange.com/a/169/15292 +function! s:handle_large_file() abort + let g:large_file = 10485760 " 10MB + let f = expand("<afile>") + + if getfsize(f) > g:large_file || getfsize(f) == -2 + set eventignore+=all + " turning off relative number helps a lot + set norelativenumber + setlocal noswapfile bufhidden=unload buftype=nowrite undolevels=-1 + else + set eventignore-=all relativenumber + endif +endfunction + +augroup LargeFile + autocmd! + autocmd BufReadPre * call s:handle_large_file() +augroup END |
