How do I profile Vim startup time to find out which plugins are slowing it down?
Answer
vim --startuptime /tmp/vim-startup.log +qall && sort -k2 -rn /tmp/vim-startup.log | head -20
Explanation
When Vim starts slowly, the --startuptime flag writes a timestamped log of every script and plugin loaded during initialization. Sorting by the second column (elapsed self-time) reveals the biggest offenders at a glance.
How it works
--startuptime {file}tells Vim to write profiling data to{file}while loading- Each line records three time columns: total elapsed, self (exclusive) time, and source file
+qallopens Vim and immediately quits so you capture startup overhead without interactive usesort -k2 -rnsorts numerically in reverse by the self-time column so the slowest entries appear firsthead -20shows only the top 20 worst offenders
Example
$ vim --startuptime /tmp/vim-startup.log +qall
$ sort -k2 -rn /tmp/vim-startup.log | head -5
342.100 123.450 000.000: sourcing /usr/share/vim/autoload/slow_plugin.vim
82.340 80.210 000.000: sourcing ~/.vim/pack/plugins/start/heavy.vim
45.001 44.800 000.000: sourcing ~/.vim/plugin/legacy.vim
The second column is the time (in milliseconds) spent exclusively in that file. Files above ~30ms are worth investigating.
Tips
- For Neovim, the flag is the same:
nvim --startuptime /tmp/nvim-startup.log +qall - Run several times and compare results since cold-start I/O can skew numbers
- Consider lazy-loading plugins that appear near the top of the list
:set loadplugins?can confirm whether plugins are even loading in a given context