You can combine autocommands with the
getfsize(file) function to automatically disable options for large files.
" A global variable that contains the size of which a file is considered
" large. In this case, it is 10 megabytes.
let g:large_file = 1024 * 1024 * 10
" This autocmd runs before reading the file into the buffer. It
" gets the file that the autocmd is running on by running expand on
" <afile>, which is short for the path to the file that the autocmd
" is running on. Then, it gets the size of the file running
" getfsize on the file and sees if it is larger than the size
" specified in g:large_file. If it is, it disables the swap file.
autocmd BufReadPre * let f=expand("<afile>") | if getfsize(f)
\ > g:large_file | set noswapfile | endif
Note that you can add any other options you want where
set noswapfile is to improve performance on large files. If you have a lot of them, you might want to create a function which sets all of them, and then add a call to that function where
set noswapfile is.
Related to performance when editing large files, here are some options that can help:
For instance, those options can be set to the below for better performance:
setlocal bufhidden=unload " (save memory when other file is viewed)
setlocal buftype=nowrite " (is read-only)
setlocal eventignore+=Filetype " (ignores autocommands with FileType as their trigger event)
setlocal undolevels=-1 " (no undo possible)
Related help topics:
I got some of this information from http://vim.wikia.com/wiki/Faster_loading_of_large_files which has useful information on performance when editing large files.