Vim is the wrong tool for the job: you should use a pager like more
or less
.
If you insist on using an editor, try this tip onexample adapted from the Vim wiki.:
augroup LargeFile
let g:large_file = 10485760 " 10MB
" Set options:
" eventignore+=FileType (no syntax highlighting etc
" assumes FileType always on)
" noswapfile (save copy of file)
" bufhidden=unload (save memory when other file is viewed)
" buftype=nowritefile (is read-only)
" undolevels=-1 (no undo possible)
au BufReadPre *
\ let f=expand("<afile>") |
\ if getfsize(f) > g:large_file |
\ set eventignore+=FileType |
\ setlocal noswapfile bufhidden=unload buftype=nowrite undolevels=-1 |
\ else |
\ set eventignore-=FileType |
\ endif
augroup END