2014-01-17 26 views
2

这是My vimrc如何缩短vim的启动时间?

我发现负载的.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

[[email protected] ~] 
$ 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配置只需要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 --- 
+1

你怎么知道你的vim开始花了1.47s? startuptime文件有'ms'。并且你的命令'time vim'的结果没有意义,这取决于你退出vim的速度。如果你打开vim并等待5分钟,然后退出,真实会是5分钟。 – Kent

+0

好吧,我现在不等5分钟,但是我的vim开始真的很慢。 – Marslo

+0

@Kent我应该从时钟(第一列)计算吗? – Marslo

回答

8

~/.vimrc其来源,这意味着每行是Vim在初始化评估,包括所有的功能。你应该将所有的函数移动到autoload目录。有关详细信息,请参阅: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不需要解析f直到它真的被调用。


另一种优化可以将所有的autocmd FileType适当的ftplugins。

现在,在您的~/.vimrc

autocmd FileType ruby setlocal something 

后,~/.vim/after/ftplugin/ruby.vim

setlocal something 
+0

你的意思是我应该把我的功能变成一个插件吗? – Marslo

+0

不是。它的想法是将它们移开,以便vim在源代码vimrc时不会对它们进行评估。这就是'autoload'的重点。 – romainl

+0

好的,谢谢。我会试一试。 – Marslo

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映射),就会加载最后一个。

还有一种方法可以将插件集分组为功能,并一次加载它们(例如通过热键或手动加载)。

+0

“什么文件类型被打开”是指?如果我在vimrc中设置'fileytype plugin indent',意味着所有的文件类型都打开了? – Marslo

+0

这意味着一旦打开特定的文件类型,该插件就会加载。这是你可以通过'au'轻松完成的事情,但这不是好的方法:命令从插件加载解耦,而不应该是。此外,NeoBundleLazy支持一堆更难的单一命令完成的选项,如果你想使用它们,它会让你的vimrc变得丑陋。 – majkinetor