0%

VIM启动时间优化

startuptime

vim 安装大量插件之后导致启动变慢,可以通过以下命令来排查各个插件的启动时间:

vim --startuptime vim.log

vim.log 中保存了启动时间信息:

000.003  000.003: --- VIM STARTING ---                                        
000.068  000.065: Allocated generic buffers                                   
000.092  000.024: locale set                                                  
000.102  000.010: GUI prepared                                                
000.105  000.003: clipboard setup                                             
000.109  000.004: window checked                                              
000.584  000.475: inits 1                                                     
000.588  000.004: parsing arguments                                           
000.589  000.001: expanding arguments                                         
000.595  000.006: shell init                                                  
000.779  000.184: Termcap init                                                
000.810  000.031: inits 2                                                     
000.903  000.093: init highlight                            

Profiling

help cmd

--cmd {command}                        *--cmd*
        {command} will be executed before processing any vimrc file.
        Otherwise it acts like -c {command}.  You can use up to 10 of
        these commands, independently from "-c" commands.
        {not in Vi}

-c {command}    {command} will be executed after the first file has been
        read (and after autocommands and modelines for that file have
        been processed).  "command" is interpreted as an Ex command.
        If the "command" contains spaces, it must be enclosed in
        double quotes (this depends on the shell that is used).
help profile

For example, to profile the one_script.vim script file: >
    :profile start /tmp/one_script_profile
    :profile file one_script.vim
    :source one_script.vim
    :exit


:prof[ile] start {fname}            *:prof* *:profile* *E750*
:prof[ile] func {pattern}
:prof[ile][!] file {pattern}
vim --cmd 'profile start profile.log' \
    --cmd 'profile func *' \
    --cmd 'profile file *' \
    -c 'profdel func *' \
    -c 'profdel file *' \
    -c 'qa!'

Plugin

vim-plugins-profile用于优化

sudo apt-get install r-base

python

vim-profiler

./vim-profiler.py
Running vim to generate startup logs... done.
Loading and processing logs... done.
Plugin directory: /home/yanwzh/.vim/bundle
====================================
Top 10 plugins slowing vim's startup
====================================
1    29.111   TagHighlight
2    21.479   nerdtree
3    18.853   c.vim
4    11.260   FuzzyFinder
5     6.034   vim-easymotion
6     4.738   unite.vim
7     4.680   vim-airline
8     1.427   vim-sensible
9     1.365   Tagbar
10    1.344   nerdtree-git-plugin

Ref

  1. Profiling Vim startup time