Faster loading of large files
From Vim Tips Wiki
created 2002 · complexity intermediate · author Erik Remmelzwaal · version 6.0
A user can sometimes experience long load times on very large files. While the definition of a very large file depends on the user, their machine specifications, and their patience, at one point or another any user can experience a load time delay. A method to load these files faster is to remove some of the options available like undo histories, syntax parsing, and swap file creation.
By adding the following to the .vimrc file, the user can automatically remove certain options for files over a certain size (in this example, 10mb).
:let g:LargeFile=10 :e
" Protect large files from sourcing and other overhead. " Files become read only if !exists("my_auto_commands_loaded") let my_auto_commands_loaded = 1 " Large files are > 10M " 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) let g:LargeFile = 1024 * 1024 * 10 augroup LargeFile autocmd BufReadPre * let f=expand("<afile>") | if getfsize(f) > g:LargeFile | set eventignore+=FileType | setlocal noswapfile bufhidden=unload buftype=nowrite undolevels=-1 | else | set eventignore-=FileType | endif augroup END endif
 See also
- Edit large files quickly plugin to handle many of the above changes and more