This is My vimrc
I found load .vimrc would take long time in terminal:
$ vim --startuptime myvimrctime
$ cat myvimrctime
....
152.762 147.219 054.849: sourcing $HOME/.vimrc
....
I've done some optimization for viminfo:
set viminfo=%,<800,'10,/50,:100,h,f0,n~/.vim/cache/.viminfo
But it still take too much time.
This is time vim
:
[marslo@MarsloJiao ~]
$ time vim
real 0m1.877s
user 0m0.204s
sys 0m0.028s
How can I reduce the startup time for my vim? Thanks.
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
And the strange is, the clock from 054.490 jump to 141.158 by no reason (vundle config only take 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
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 ---
Your ~/.vimrc
is sourced, it means that every line is evaluated by Vim upon initialization, including all your functions. You should move all your functions to the autoload directory. See :help autoload
for the details but here is a simplified example.
If you had this in your ~/.vimrc
:
function! MyFunc()
" code
endfunction
autocmd BufWinEnter * call MyFunc()
You could create ~/.vim/autoload/functions.vim
and move the function in there:
function functions#MyFunc()
" code
endfunction
and leave just this in your ~/.vimrc
:
autocmd BufWinEnter * call functions#MyFunc()
In that form Vim will not need to parse the function until it is actually called.
Another optimization could be to move all your autocmd FileType
to proper ftplugins.
Now, in your ~/.vimrc
:
autocmd FileType ruby setlocal something
After, in ~/.vim/after/ftplugin/ruby.vim
:
setlocal something
Perhaps you should switch from Vundle to NeoBundle. It has NeoBundleLazy
option that automatically loads plugin only when it is requested. Its upon you to decide how is this achieved. It supports activation by command, mapping, filetype, calls by other plugins like unite
, etc.
For instance, take a look at parts from my 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)']] }
Above code means that first 3 plugins will be loaded only when specific file types are opened but last one will load as soon as you press mapping defined by plugin (which itself is mapped by cmap
).
There is also a way to group your plugin sets into functions and load them all at once (via hotkey for example or manually).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With