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("") + + 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