分類  >  綜合 >

對vim/gvim進展啟動精簡的探討

tags:    時間:2014-05-04 18:54:07
對vim/gvim進行啟動精簡的探討.

前言: 

     用了很久的vim, 插件裝得越來越多, 輸入vim/gvim后打開項目越來越慢? 這個時候我們有必要引入一些方法來精簡vim了.


導致vim變慢的情況, 需要具體分析一下.  是不是在不久前裝了幾款插件后, 發現啟動gtk的vim卡了不少? 打開單行超過80字元的時候非常卡? 




vim啟動的時候有一個參數, --startuptime 我們可以利用它來查看啟動載入.

#gvim --startuptime 'time.txt'  

然後打開當前目錄下的time.txt 這個文件,  就是下面的這個文件. 左邊第一列 A 是總耗時, 單位是微秒, 以 . 隔開, 比如 438.809 表示的是0.438809秒 , 第二列 B 是 該步驟載入耗時, 第三列 C 是該步驟載入完耗時, 第四列 D 是來源. 

times in msec  clock   self+sourced   self:  sourced script  clock   elapsed:              other lines   A        B           C            D 000.011  000.011: --- VIM STARTING --- 000.156  000.145: Allocated generic buffers 000.235  000.079: locale set 000.254  000.019: GUI prepared 000.258  000.004: clipboard setup 000.268  000.010: window checked 000.893  000.625: inits 1 000.921  000.028: parsing arguments 000.925  000.004: expanding arguments 000.938  000.013: shell init 001.192  000.254: Termcap init 001.231  000.039: inits 2 001.331  000.100: init highlight 015.966  000.046  000.046: sourcing /usr/share/vim/vim74/autoload/paste.vim 024.677  009.375  009.329: sourcing /usr/share/vim/vim74/menu.vim 024.737  023.248  013.873: sourcing /usr/share/vim/vim74/filetype.vim 024.821  000.015  000.015: sourcing /usr/share/vim/vim74/filetype.vim 024.918  000.057  000.057: sourcing /usr/share/vim/vim74/ftplugin.vim 024.973  000.013  000.013: sourcing /usr/share/vim/vim74/filetype.vim 025.058  000.047  000.047: sourcing /usr/share/vim/vim74/indent.vim 025.113  000.013  000.013: sourcing /usr/share/vim/vim74/filetype.vim 025.162  000.013  000.013: sourcing /usr/share/vim/vim74/ftplugin.vim 025.208  000.012  000.012: sourcing /usr/share/vim/vim74/indent.vim 025.982  000.268  000.268: sourcing /usr/share/vim/vim74/delmenu.vim 026.996  000.732  000.732: sourcing /usr/share/vim/vim74/lang/menu_zh_cn.utf-8.vim 040.745  014.666  013.934: sourcing /usr/share/vim/vim74/menu.vim 041.243  000.344  000.344: sourcing /usr/share/vim/vim74/colors/desert.vim 041.542  000.261  000.261: sourcing /usr/share/vim/vim74/colors/desert.vim 041.967  000.183  000.183: sourcing /usr/share/vim/vim74/syntax/syncolor.vim 042.211  000.155  000.155: sourcing /usr/share/vim/vim74/syntax/syncolor.vim 042.353  000.688  000.350: sourcing /usr/share/vim/vim74/colors/desert.vim 042.456  000.830  000.142: sourcing /usr/share/vim/vim74/syntax/synload.vim 042.491  000.903  000.073: sourcing /usr/share/vim/vim74/syntax/syntax.vim 042.761  000.200  000.200: sourcing /usr/share/vim/vim74/syntax/nosyntax.vim 043.140  000.159  000.159: sourcing /usr/share/vim/vim74/syntax/syncolor.vim 043.396  000.160  000.160: sourcing /usr/share/vim/vim74/syntax/syncolor.vim 043.540  000.696  000.377: sourcing /usr/share/vim/vim74/colors/desert.vim 043.638  000.834  000.138: sourcing /usr/share/vim/vim74/syntax/synload.vim 043.682  001.155  000.121: sourcing /usr/share/vim/vim74/syntax/syntax.vim 045.988  000.449  000.449: sourcing /usr/share/vim/vim74/syntax/javascript.vim 049.264  003.119  003.119: sourcing /usr/share/vim/vim74/syntax/vb.vim 050.719  001.329  001.329: sourcing /usr/share/vim/vim74/syntax/css.vim 051.168  006.383  001.486: sourcing /usr/share/vim/vim74/syntax/html.vim 051.518  000.207  000.207: sourcing /usr/share/vim/vim74/syntax/sqloracle.vim 051.528  000.277  000.070: sourcing /usr/share/vim/vim74/syntax/sql.vim 054.714  010.014  003.354: sourcing /usr/share/vim/vim74/syntax/php.vim 056.148  054.779  003.750: sourcing $VIM/vimrc 056.180  000.070: sourcing vimrc file(s) 089.372  032.824  032.824: sourcing /usr/share/vim/vim74/plugin/EasyGrep.vim 089.810  000.342  000.342: sourcing /usr/share/vim/vim74/autoload/EasyMotion.vim 091.358  001.935  001.593: sourcing /usr/share/vim/vim74/plugin/EasyMotion.vim 094.438  003.051  003.051: sourcing /usr/share/vim/vim74/plugin/NERD_tree.vim 095.425  000.274  000.274: sourcing /usr/share/vim/vim74/autoload/acp.vim 095.628  001.153  000.879: sourcing /usr/share/vim/vim74/plugin/acp.vim 095.776  000.124  000.124: sourcing /usr/share/vim/vim74/plugin/authorinfo.vim 096.881  001.078  001.078: sourcing /usr/share/vim/vim74/plugin/bufexplorer.vim 097.771  000.859  000.859: sourcing /usr/share/vim/vim74/plugin/calendar.vim 098.011  000.212  000.212: sourcing /usr/share/vim/vim74/plugin/closetag.vim 106.485  008.451  008.451: sourcing /usr/share/vim/vim74/plugin/colorizer.vim 107.131  000.306  000.306: sourcing /usr/share/vim/vim74/autoload/colorv/data.vim 135.301  000.204  000.204: sourcing /usr/share/vim/vim74/autoload/colorv/mark.vim 135.421  000.076  000.076: sourcing /usr/share/vim/vim74/autoload/colorv/cache.vim 136.253  000.660  000.660: sourcing /usr/share/vim/vim74/autoload/colorv/scheme.vim 136.487  029.797  028.551: sourcing /usr/share/vim/vim74/autoload/colorv.vim 138.182  031.660  001.863: sourcing /usr/share/vim/vim74/plugin/colorv.vim 138.352  000.135  000.135: sourcing /usr/share/vim/vim74/plugin/csExplorer.vim 138.918  000.405  000.405: sourcing /usr/share/vim/vim74/autoload/ctrlp/mrufiles.vim 139.077  000.703  000.298: sourcing /usr/share/vim/vim74/plugin/ctrlp.vim 139.180  000.081  000.081: sourcing /usr/share/vim/vim74/plugin/getscriptPlugin.vim 139.949  000.748  000.748: sourcing /usr/share/vim/vim74/plugin/grep.vim 140.169  000.197  000.197: sourcing /usr/share/vim/vim74/plugin/gzip.vim 140.902  000.712  000.712: sourcing /usr/share/vim/vim74/plugin/matchit.vim 141.095  000.169  000.169: sourcing /usr/share/vim/vim74/plugin/matchparen.vim 142.512  001.394  001.394: sourcing /usr/share/vim/vim74/plugin/minibufexpl.vim 145.397  002.862  002.862: sourcing /usr/share/vim/vim74/plugin/mru.vim 150.262  004.828  004.828: sourcing /usr/share/vim/vim74/plugin/multisearch.vim 150.751  000.460  000.460: sourcing /usr/share/vim/vim74/plugin/netrwPlugin.vim 150.817  000.039  000.039: sourcing /usr/share/vim/vim74/plugin/rrhelper.vim 150.870  000.032  000.032: sourcing /usr/share/vim/vim74/plugin/spellfile.vim 151.016  000.126  000.126: sourcing /usr/share/vim/vim74/plugin/statusline.vim 151.555  000.516  000.516: sourcing /usr/share/vim/vim74/plugin/surround.vim 152.075  000.493  000.493: sourcing /usr/share/vim/vim74/plugin/taglist.vim 152.279  000.177  000.177: sourcing /usr/share/vim/vim74/plugin/tarPlugin.vim 152.371  000.068  000.068: sourcing /usr/share/vim/vim74/plugin/tohtml.vim 152.415  000.023  000.023: sourcing /usr/share/vim/vim74/plugin/txt.vim 152.595  000.157  000.157: sourcing /usr/share/vim/vim74/plugin/vimballPlugin.vim 152.640  000.019  000.019: sourcing /usr/share/vim/vim74/plugin/vimcdoc.vim 153.554  000.886  000.886: sourcing /usr/share/vim/vim74/plugin/winfileexplorer.vim 154.417  000.832  000.832: sourcing /usr/share/vim/vim74/plugin/winmanager.vim 154.725  000.280  000.280: sourcing /usr/share/vim/vim74/plugin/wintagexplorer.vim 156.538  001.788  001.788: sourcing /usr/share/vim/vim74/plugin/zencoding.vim 156.762  000.193  000.193: sourcing /usr/share/vim/vim74/plugin/zipPlugin.vim 156.787  001.342: loading plugins 156.797  000.010: inits 3 169.794  001.861  001.861: sourcing $VIMRUNTIME/menu.vim 170.075  000.202  000.202: sourcing $VIM/gvimrc 411.511  252.651: starting GUI 412.239  000.728: reading viminfo 412.594  000.355: GUI delay 412.598  000.004: setting raw mode 412.599  000.001: start termcap 412.637  000.038: clearing screen 419.274  000.701  000.701: sourcing /usr/share/vim/vim74/scripts.vim 420.916  007.578: opening buffers 421.829  000.913: BufEnter autocommands 421.831  000.002: editing files in windows 425.198  003.367: VimEnter autocommands 425.202  000.004: before starting main loop 433.756  008.554: first screen update 433.759  000.003: --- VIM STARTED --- 



可以看見, 上面比較耗時的有GUI, menu,filetype,php,colorv 等插件和組件. 對於插件, 如果不是特別需要, 可以直接刪除掉.

現在開始作實驗:

首先是針對GUI, 我們使用vim 來代替剛才的啟動,  可以得到結果, 沒有GUI這項后啟動時間大幅縮減.  結論, 沒有gui的vim目前是最快的.

143.895  000.018: inits 3 144.595  000.700: reading viminfo 149.386  004.791: setup clipboard 149.420  000.034: setting raw mode 149.431  000.011: start termcap 149.468  000.037: clearing screen 150.476  001.008: opening buffers 151.790  001.314: BufEnter autocommands 151.794  000.004: editing files in windows 186.932  035.138: VimEnter autocommands 186.936  000.004: before starting main loop 188.833  001.897: first screen update 188.835  000.002: --- VIM STARTED --- 

針對filetype, menu 這幾個功能上的選項, 因為是功能上的, 如果精簡掉, 會導致我們想要的vim的功能上的缺失. 所以是去是留看個人了.

針對插件, 直接刪除掉即可. 如果不是必須的, 也可以重寫插件.

針對vimrc文件的載入時間. 可以通過優化內容, 壓縮空行, 壓縮註釋來實現. 我的vimrc 之前有1600行. 現在刪除一些配置, 註釋, 壓縮到830行, 載入時間在3750微秒減少到了3254微秒.實際發現效果不明顯.

055.359  054.415  003.254: sourcing $VIM/vimrc 055.391  000.073: sourcing vimrc file(s) 


結論: 

    vim本身具有非常強大的功能, 非常高效的編輯效率, 通過一些插件, 我們可以更好的使用它, 熟悉它. 如果不是必要, 完全不需要把vim打造成一個全能的工具, 畢竟術業有專攻, 既然咖啡機可以煮咖啡, 為什麼要emacs來煮. 精簡刪除掉一些不必要的插件, 提高vim的啟動效率, 提高vim的穩定性, 進而提高編碼效率, 這也不失為一個好的途徑.  




推薦閱讀文章

Bookmark the permalink ,來源:互聯網