这是My vimrc
我发现加载.vimrc需要很长时间在终端:
$ vim --startuptime myvimrctime
$ cat myvimrctime
....
152.762 147.219 054.849: sourcing $HOME/.vimrc
....
我为viminfo做了一些优化:
set viminfo=%,<800,'10,/50,:100,h,f0,n~/.vim/cache/.viminfo
但它仍然需要太多时间。
这是time vim
:
[marslo@MarsloJiao ~]
$ time vim
real 0m1.877s
user 0m0.204s
sys 0m0.028s
如何减少vim的启动时间?感谢。
<小时/> 顺便说一句,这里有三个项目也需要花费很多时间,有什么办法可以在vim启动后启动这些文件:
050.213 043.340 043.340: sourcing /home/marslo/.vim/tools/vim74/share/vim/vim74/filetype.vim
050.334 044.509 000.409: sourcing /home/marslo/.vim/tools/vim74/share/vim/vim74/syntax/syntax.vim
143.985 040.931 037.467: sourcing /home/marslo/.vim/tools/vim74/share/vim/vim74/filetype.vim
奇怪的是, 054.490 的时钟无缘无故地跳到 141.158 (vundle config只取000.184):
054.490 000.184 000.184: sourcing /home/marslo/.vim/bundle/vundle/autoload/vundle/config.vim
141.158 002.377 002.377: sourcing /home/marslo/.vim/bundle/vim-ruby/ftdetect/ruby.vim
<小时/> 我再次创建了新的--startuptime文件。以下是完整日志:
times in msec
clock self+sourced self: sourced script
clock elapsed: other lines
000.013 000.013: --- VIM STARTING ---
050.538 050.525: Allocated generic buffers
110.662 060.124: locale set
124.156 013.494: GUI prepared
222.567 098.411: clipboard setup
222.610 000.043: window checked
465.327 242.717: inits 1
465.344 000.017: parsing arguments
465.348 000.004: expanding arguments
465.383 000.035: shell init
465.846 000.463: Termcap init
465.912 000.066: inits 2
466.107 000.195: init highlight
682.019 000.574 000.574: sourcing /home/marslo/.vim/tools/vim74/share/vim/vim74/syntax/syncolor.vim
682.360 001.624 001.050: sourcing /home/marslo/.vim/tools/vim74/share/vim/vim74/syntax/synload.vim
740.232 031.815 031.815: sourcing /home/marslo/.vim/tools/vim74/share/vim/vim74/filetype.vim
740.351 073.003 039.564: sourcing /home/marslo/.vim/tools/vim74/share/vim/vim74/syntax/syntax.vim
740.490 000.023 000.023: sourcing /home/marslo/.vim/tools/vim74/share/vim/vim74/filetype.vim
784.275 000.101 000.101: sourcing /home/marslo/.vim/tools/vim74/share/vim/vim74/ftplugin.vim
863.519 056.517 056.517: sourcing /home/marslo/.vim/tools/vim74/share/vim/vim74/macros/matchit.vim
865.282 001.188 001.188: sourcing /home/marslo/.vim/tools/vim74/share/vim/vim74/ftoff.vim
1000.218 000.258 000.258: sourcing /home/marslo/.vim/bundle/vundle/autoload/vundle.vim
1054.471 000.234 000.234: sourcing /home/marslo/.vim/bundle/vundle/autoload/vundle/config.vim
1585.009 002.401 002.401: sourcing /home/marslo/.vim/bundle/vim-ruby/ftdetect/ruby.vim
1589.847 000.516 000.516: sourcing /home/marslo/.vim/bundle/vim-javascript/ftdetect/javascript.vim
1600.298 000.232 000.232: sourcing /home/marslo/.vim/bundle/vim-javascript-syntax/ftdetect/javascript.vim
1609.818 000.376 000.376: sourcing /home/marslo/.vim/bundle/vim-markdown/ftdetect/mkd.vim
1638.215 124.558 121.033: sourcing /home/marslo/.vim/tools/vim74/share/vim/vim74/filetype.vim
1640.109 000.055 000.055: sourcing /home/marslo/.vim/tools/vim74/share/vim/vim74/ftplugin.vim
1651.369 000.189 000.189: sourcing /home/marslo/.vim/tools/vim74/share/vim/vim74/indent.vim
1681.203 000.767 000.767: sourcing /home/marslo/.vim/tools/vim74/share/vim/vim74/syntax/syncolor.vim
1686.380 000.729 000.729: sourcing /home/marslo/.vim/tools/vim74/share/vim/vim74/syntax/syncolor.vim
1689.126 000.719 000.719: sourcing /home/marslo/.vim/tools/vim74/share/vim/vim74/syntax/syncolor.vim
1691.276 027.443 025.228: sourcing /home/marslo/.vim/bundle/marslo.vim/colors/marslo256.vim
1692.803 1160.345 877.776: sourcing $HOME/.vimrc
1692.839 066.387: sourcing vimrc file(s)
1720.420 000.418 000.418: sourcing /home/marslo/.vim/bundle/ctrlp.vim/autoload/ctrlp/mrufiles.vim
1720.883 009.810 009.392: sourcing /home/marslo/.vim/bundle/ctrlp.vim/plugin/ctrlp.vim
1742.318 001.396 001.396: sourcing /home/marslo/.vim/bundle/tagbar/plugin/tagbar.vim
1747.987 000.292 000.292: sourcing /home/marslo/.vim/bundle/authorinfo/plugin/authorinfo.vim
1758.222 003.409 003.409: sourcing /home/marslo/.vim/bundle/EnhCommentify.vim/plugin/EnhancedCommentify.vim
1779.670 002.103 002.103: sourcing /home/marslo/.vim/bundle/supertab/plugin/supertab.vim
1788.557 001.838 001.838: sourcing /home/marslo/.vim/bundle/auto-pairs/plugin/auto-pairs.vim
1809.937 001.491 001.491: sourcing /home/marslo/.vim/bundle/snipmate.vim/plugin/snipMate.vim
1813.891 000.471 000.471: sourcing /home/marslo/.vim/bundle/Conque-Shell/plugin/conque_term.vim
1854.376 019.755 019.755: sourcing /home/marslo/.vim/bundle/mru.vim/plugin/mru.vim
1856.948 001.377 001.377: sourcing /home/marslo/.vim/bundle/taglist.vim/plugin/taglist.vim
1877.552 003.597 003.597: sourcing /home/marslo/.vim/bundle/winmanager/plugin/winfileexplorer.vim
1882.273 004.192 004.192: sourcing /home/marslo/.vim/bundle/winmanager/plugin/winmanager.vim
1894.960 001.489 001.489: sourcing /home/marslo/.vim/bundle/winmanager/plugin/wintagexplorer.vim
1918.938 000.482 000.482: sourcing /home/marslo/.vim/bundle/python_fold/plugin/python_fold.vim
1944.447 001.214 001.214: sourcing /home/marslo/.vim/bundle/vim-rails/plugin/rails.vim
1998.414 002.073 002.073: sourcing /home/marslo/.vim/bundle/vim-textobj-user/autoload/textobj/user.vim
2015.845 048.452 046.379: sourcing /home/marslo/.vim/bundle/vim-textobj-rubyblock/plugin/textobj/rubyblock.vim
2034.279 000.329 000.329: sourcing /home/marslo/.vim/bundle/ruby-matchit/plugin/ruby-matchit.vim
2063.907 001.131 001.131: sourcing /home/marslo/.vim/bundle/vim-surround/plugin/surround.vim
2105.056 018.511 018.511: sourcing /home/marslo/.vim/bundle/rainbow/plugin/rainbow.vim
2130.447 000.401 000.401: sourcing /home/marslo/.vim/tools/vim74/share/vim/vim74/plugin/getscriptPlugin.vim
2131.959 000.904 000.904: sourcing /home/marslo/.vim/tools/vim74/share/vim/vim74/plugin/gzip.vim
2132.955 000.557 000.557: sourcing /home/marslo/.vim/tools/vim74/share/vim/vim74/plugin/matchparen.vim
2134.955 001.501 001.501: sourcing /home/marslo/.vim/tools/vim74/share/vim/vim74/plugin/netrwPlugin.vim
2135.455 000.100 000.100: sourcing /home/marslo/.vim/tools/vim74/share/vim/vim74/plugin/rrhelper.vim
2135.852 000.084 000.084: sourcing /home/marslo/.vim/tools/vim74/share/vim/vim74/plugin/spellfile.vim
2136.666 000.501 000.501: sourcing /home/marslo/.vim/tools/vim74/share/vim/vim74/plugin/tarPlugin.vim
2137.312 000.215 000.215: sourcing /home/marslo/.vim/tools/vim74/share/vim/vim74/plugin/tohtml.vim
2137.972 000.335 000.335: sourcing /home/marslo/.vim/tools/vim74/share/vim/vim74/plugin/vimballPlugin.vim
2138.870 000.540 000.540: sourcing /home/marslo/.vim/tools/vim74/share/vim/vim74/plugin/zipPlugin.vim
2157.065 000.696 000.696: sourcing /home/marslo/.vim/bundle/indentLine/after/plugin/indentLine.vim
2184.847 006.999 006.999: sourcing /home/marslo/.vim/bundle/snipmate.vim/after/plugin/snipMate.vim
2185.397 359.386: loading plugins
2187.454 002.057: inits 3
2195.983 008.529: reading viminfo
2242.679 046.696: setup clipboard
2242.716 000.037: setting raw mode
2242.760 000.044: start termcap
2242.859 000.099: clearing screen
2247.092 004.233: opening buffers
2248.580 001.488: BufEnter autocommands
2248.593 000.013: editing files in windows
2249.224 000.631: VimEnter autocommands
2249.231 000.007: before starting main loop
2251.990 002.759: first screen update
2251.999 000.009: --- VIM STARTED ---
答案 0 :(得分:10)
您的~/.vimrc
来源,这意味着Vim在初始化时会评估每一行,包括您的所有功能。您应该将所有功能移动到自动加载目录。有关详细信息,请参阅:help autoload
,但这是一个简化示例。
如果您在~/.vimrc
:
function! MyFunc()
" code
endfunction
autocmd BufWinEnter * call MyFunc()
您可以创建~/.vim/autoload/functions.vim
并在其中移动该功能:
function functions#MyFunc()
" code
endfunction
并将此保留在~/.vimrc
:
autocmd BufWinEnter * call functions#MyFunc()
在这种形式下,Vim在实际调用之前不需要解析函数。
另一个优化可能是将所有autocmd FileType
移动到正确的ftplugins。
现在,在~/.vimrc
:
autocmd FileType ruby setlocal something
之后,在~/.vim/after/ftplugin/ruby.vim
:
setlocal something
答案 1 :(得分:4)
也许您应该从Vundle切换到NeoBundle。它具有NeoBundleLazy
选项,仅在请求时自动加载插件。它由你决定如何实现。它支持通过命令,映射,文件类型,其他插件(如unite
等)的调用进行激活。
例如,看看我的vimrc中的部分:
NeoBundleLazy 'klen/python-mode' , { 'filetypes' : ['python'] }
NeoBundleLazy 'Decho' , { 'filetypes' : ['vim'] }
NeoBundleLazy 'othree/html5.vim' , { 'filetypes' : [ 'html', 'css' ] } }
NeoBundleLazy 'majkinetor/unite-cmdmatch' , { 'depends': 'Shougo/unite.vim' , 'mappings' : [['c' , '<Plug>(unite_cmdmatch_complete)']] }
上面的代码意味着只有在打开特定文件类型时才会加载前3个插件,但是只要按下插件定义的映射(它本身由cmap
映射),最后一个插件就会加载。
还有一种方法可以将插件集分组为函数并一次性加载它们(例如通过热键或手动)。