5

When investigating the vim startup time with --startup option, I see lots of files are sourced multiple times.

Could anyone explain to me why?

After vim --startuptime vim-startup then sort -k 4 vim-startup, scroll to end of output. There are many line sourcing /usr/local/share/vim/vim74/syntax/syncolor.vim are repeated

717.204  000.149  000.149: sourcing /usr/local/share/vim/vim74/plugin/getscriptPlugin.vim
717.635  000.394  000.394: sourcing /usr/local/share/vim/vim74/plugin/gzip.vim
718.072  000.400  000.400: sourcing /usr/local/share/vim/vim74/plugin/logiPat.vim
718.416  000.305  000.305: sourcing /usr/local/share/vim/vim74/plugin/matchparen.vim
719.372  000.917  000.917: sourcing /usr/local/share/vim/vim74/plugin/netrwPlugin.vim
719.480  000.058  000.058: sourcing /usr/local/share/vim/vim74/plugin/rrhelper.vim
719.596  000.074  000.074: sourcing /usr/local/share/vim/vim74/plugin/spellfile.vim
719.883  000.248  000.248: sourcing /usr/local/share/vim/vim74/plugin/tarPlugin.vim
720.119  000.192  000.192: sourcing /usr/local/share/vim/vim74/plugin/tohtml.vim
720.451  000.290  000.290: sourcing /usr/local/share/vim/vim74/plugin/vimballPlugin.vim
720.828  000.325  000.325: sourcing /usr/local/share/vim/vim74/plugin/zipPlugin.vim
288.036  000.351  000.351: sourcing /usr/local/share/vim/vim74/syntax/syncolor.vim
355.569  000.211  000.211: sourcing /usr/local/share/vim/vim74/syntax/syncolor.vim
358.687  000.412  000.412: sourcing /usr/local/share/vim/vim74/syntax/syncolor.vim
403.346  000.541  000.541: sourcing /usr/local/share/vim/vim74/syntax/syncolor.vim
406.806  000.277  000.277: sourcing /usr/local/share/vim/vim74/syntax/syncolor.vim
416.571  000.370  000.370: sourcing /usr/local/share/vim/vim74/syntax/syncolor.vim
419.967  000.456  000.456: sourcing /usr/local/share/vim/vim74/syntax/syncolor.vim
429.839  000.280  000.280: sourcing /usr/local/share/vim/vim74/syntax/syncolor.vim
433.602  000.382  000.382: sourcing /usr/local/share/vim/vim74/syntax/syncolor.vim
289.756  004.047  003.696: sourcing /usr/local/share/vim/vim74/syntax/synload.vim
413.308  013.091  001.653: sourcing /usr/local/share/vim/vim74/syntax/synload.vim
289.809  005.994  001.947: sourcing /usr/local/share/vim/vim74/syntax/syntax.vim
413.370  015.529  001.789: sourcing /usr/local/share/vim/vim74/syntax/syntax.vim
1240.101  000.004: before starting main loop
737.049  000.020: start termcap
736.993  000.202: reading viminfo
442.780  000.558: sourcing vimrc file(s)

Could anyone explain to me why vim needs to source one file multiple times or how can I force it to load once?

Here are full output of vim --startup: before and after sort, nvim --startuptime: before and after sort

Sang
  • 4,049
  • 3
  • 37
  • 47

2 Answers2

1

Looking at your vim --startup output, it looks like many other scripts are loaded multiple times. The script below, for example, is sourced four times:

/Users/nissassin17/.vim/bundle/xptemplate/plugin/classes/FiletypeScope.vim

and there are many others.

You also seem to be loading the original solarized colorscheme three times and the "base-16" variant after that which makes no sense at all and would probably count as a cause for the multiple sourcing of /usr/local/share/vim/vim74/syntax/syntax.vim.

I can't go further without seeing your vimrc but I'd suggest deleting the content of ~/.vim/bundle/and starting over.

Maybe with less plugins?

romainl
  • 186,200
  • 21
  • 280
  • 313
  • after debugging, I figured out that with each`color `, `vim` loads `sourcing /usr/local/Cellar/neovim/HEAD/share/nvim/runtime/syntax/syncolor.vim` once. For others, the mechanism maybe same. I am currently using [spf13-vim](https://github.com/spf13/spf13-vim), and [this](https://github.com/nissassin17/vim-config) is my local config files. See `source` folder Now I have no ideal to force `vim` loading one file once – Sang Mar 10 '16 at 10:27
  • to a) Do you mean that I should drop spf-13 to avoid repeat sourcing. If possible, could you explain me why `vim` does not keep track of file each loading (in a dictionary, smt like `loadIfAbsent`) to b) I publish for personal use, because I usually have to switch working environment (reinstall OS,new PC, etc...). Btw, thank you for your advice – Sang Mar 10 '16 at 12:35
  • 1
    a) If you are a newbie, "distributions" like spf-13 actively prevent you from learning. If you already have some experience *you* certainly already have *your* own config tailored to *your* needs. In any case, using such a package completely defeats the purpose of using a tool as customizable as Vim. Make it yours, not someone else's. Also… no, Vim doesn't have the kind of unified API that would prevent that kind of mishap. b) Then don't publish or, at the very least, add some kind of warning about the nature of your repo. – romainl Mar 10 '16 at 13:11
  • a) Actually, I learned alot from spf-13, realized that there are lots of useful plugin that I didnt know ([easymotion](https://github.com/easymotion/vim-easymotion),[startify](https://github.com/mhinz/vim-startify), [rainbow](https://github.com/kien/rainbow_parentheses.vim)...). But instead of building my own new config from scratch+what I learned from spf-13, I tried using spf-13 custom (via `.local` files). b) I appreciate your advice – Sang Mar 10 '16 at 14:04
  • 1
    thank for your advice, after following it, I combined everything to my one-file configuration. And `vim`'s startup time dropped from _1.35_ second to _0.95_ second. But I also found that `youcompleteme` plugin is the most significant startup time consumer. It took roughly _0.4_ second. After `youcompleteme`'s removal, my `nvim` startup time now became just _0.4_ second – Sang Mar 15 '16 at 07:54
1

Another reason for vim/neovim to load colorscheme twice is if you have syntax on after colorscheme myscheme in your vimrc. Solution: switch them around.

DrGo
  • 411
  • 3
  • 7