为了vim好用,装了很多插件,比如neocomplete,这些插件就会让vim运行十分缓慢,所以为加载大文件提速,最好的办法就是遇到大文件时,不运行这些插件。
我采用的办法是大于1M的文件,就不使用这些插件。毕竟1M的代码文件还是非常稀少的。
脚本配置如下,把下面的脚本复制到~/.vimrc中就成,
" file is large from 1MB let g:LargeFile = 1024 * 1024 * 1 augroup LargeFile autocmd BufReadPre * let f=getfsize(expand("<afile>")) | if f > g:LargeFile || f == -2 | call LargeFile() | endif augroup END function LargeFile() " no Syntax highlighting etc
set eventignore+=FileType
" save memory when other file is viewed setlocal bufhidden=unload " is read-only (write with :w new_filename)
setlocal buftype=nowrite
" no undo possible setlocal undolevels=-1 " display message
autocmd VimEnter * echo "The file is larger than " . (g:LargeFile / 1024 ) . " MB,so some options are changed (see .vimrc for details)."
endfunction
"以上的配置文件中,当文件大于1MB,不启动语法高亮在内的一切附加功能
最后,推荐使用spf13-vim,比较好用