vim需要很长时间才能启动

时间:2013-01-31 21:16:16

标签: vim

自从我最后一次注销并重新登录以来,我在使用vim以及其他无关程序时遇到了非常缓慢的启动时间。以下是vim的启动时间日志:

> times in msec  clock   self+sourced   self:  sourced script  clock  
> elapsed:              other lines
> 
> 000.005  000.005: --- VIM STARTING ---
> 000.073  000.068: Allocated generic buffers
> 000.168  000.095: locale set
> 000.180  000.012: GUI prepared
> 000.181  000.001: clipboard setup
> 000.188  000.007: window checked
> 000.621  000.433: inits 1
> 000.626  000.005: parsing arguments
> 000.627  000.001: expanding arguments
> 000.637  000.010: shell init
> 000.909  000.272: Termcap init
> 000.942  000.033: inits 2
> 001.031  000.089: init highlight
> 023.418  000.234  000.234: sourcing /grid/common/pkgs/vim/v7.3/share/vim/vim73/syntax/syncolor.vim
> 023.543  001.811  001.577: sourcing /grid/common/pkgs/vim/v7.3/share/vim/vim73/syntax/synload.vim
> 044.397  015.231  015.231: sourcing /grid/common/pkgs/vim/v7.3/share/vim/vim73/filetype.vim
> 044.449  025.111  008.069: sourcing /grid/common/pkgs/vim/latest/share/vim/vim73/syntax/syntax.vim
> 052.532  000.199  000.199: sourcing /grid/common/pkgsData/vim-v7.3/Linux/RHEL4.0-2007-x86_64/share/vim/vim73/syntax/nosyntax.vim
> 059.858  000.175  000.175: sourcing /grid/common/pkgs/vim/v7.3/share/vim/vim73/syntax/syncolor.vim
> 059.966  003.842  003.667: sourcing /grid/common/pkgs/vim/v7.3/share/vim/vim73/syntax/synload.vim
> 060.002  010.259  006.218: sourcing /grid/common/pkgs/vim/v7.3/share/vim/vim73/syntax/syntax.vim
> 069.085  000.178  000.178: sourcing /grid/common/pkgs/vim/v7.3/share/vim/vim73/syntax/syncolor.vim
> 072.326  000.173  000.173: sourcing /grid/common/pkgs/vim/v7.3/share/vim/vim73/syntax/syncolor.vim
> 076.317  000.175  000.175: sourcing /grid/common/pkgs/vim/v7.3/share/vim/vim73/syntax/syncolor.vim
> 076.477  013.311  012.785: sourcing /grid/common/pkgs/vim/v7.3/share/vim/vim73/colors/desert.vim
> 079.768  000.019  000.019: sourcing /grid/common/pkgs/vim/v7.3/share/vim/vim73/filetype.vim
> 080.322  065.921  017.221: sourcing $HOME/.vimrc
> 080.330  013.378: sourcing vimrc file(s)
> 106.526  000.376  000.376: sourcing /home/haitham/.vim/plugin/genutils.vim
> 111.139  001.435  001.435: sourcing /home/haitham/.vim/plugin/multiselect.vim
> 113.534  000.147  000.147: sourcing /home/haitham/.vim/plugin/omap-param.vim
> 119.245  000.073  000.073: sourcing /home/haitham/.vim/plugin/qfixtoggle.vim
> 122.821  000.696  000.696: sourcing /home/haitham/.vim/plugin/surround.vim
> 172.247  000.098  000.098: sourcing /grid/common/pkgs/vim/v7.3/share/vim/vim73/plugin/getscriptPlugin.vim
> 176.387  000.252  000.252: sourcing /grid/common/pkgs/vim/v7.3/share/vim/vim73/plugin/gzip.vim
> 179.876  000.183  000.183: sourcing /grid/common/pkgs/vim/v7.3/share/vim/vim73/plugin/matchparen.vim
> 182.748  000.620  000.620: sourcing /grid/common/pkgs/vim/v7.3/share/vim/vim73/plugin/netrwPlugin.vim
> 186.171  000.051  000.051: sourcing /grid/common/pkgs/vim/v7.3/share/vim/vim73/plugin/rrhelper.vim
> 189.739  000.046  000.046: sourcing /grid/common/pkgs/vim/v7.3/share/vim/vim73/plugin/spellfile.vim
> 193.406  000.195  000.195: sourcing /grid/common/pkgs/vim/v7.3/share/vim/vim73/plugin/tarPlugin.vim
> 199.206  000.060  000.060: sourcing /grid/common/pkgs/vim/v7.3/share/vim/vim73/plugin/tohtml.vim
> 202.299  000.152  000.152: sourcing /grid/common/pkgs/vim/v7.3/share/vim/vim73/plugin/vimballPlugin.vim
> 205.345  000.147  000.147: sourcing /grid/common/pkgs/vim/v7.3/share/vim/vim73/plugin/zipPlugin.vim
> 205.394  120.533: loading plugins
> 12343.581  12138.187: inits 3
> 12349.592  006.011: reading viminfo
> 18421.239  6071.647: setup clipboard
> 18421.264  000.025: setting raw mode
> 18421.270  000.006: start termcap
> 18421.293  000.023: clearing screen
> 18421.504  000.211: opening buffers
> 18421.564  000.060: BufEnter autocommands
> 18421.566  000.002: editing files in windows
> 18425.833  004.267: VimEnter autocommands
> 18425.835  000.002: before starting main loop
> 18426.587  000.752: first screen update
> 18428.334  001.747: --- VIM STARTED ---

显然,最大的组件是“inits 3”和“setup clipboard”。

有关该怎么办的线索?

谢谢!

2 个答案:

答案 0 :(得分:64)

设置剪贴板

首先,尝试使用以下命令运行Vim:

$ vim -X

您可以尝试同时使用-X --startuptime <file>选项查看“设置剪贴板”组件是否仍然很慢。

如果-X有帮助,您可以通过在vimrc文件中添加以下行来获得相同的效果:

set clipboard=exclude:.*

说明

如果这有助于正在发生的事情是在启动时Vim正在尝试连接到X服务器以允许它使用剪贴板。 -X选项告诉Vim不要尝试连接到X服务器。来自:help -X

-X          Do not try connecting to the X server to get the current
            window title and copy/paste using the X clipboard.  This
            avoids a long startup time when running Vim in a terminal
            emulator and the connection to the X server is slow.
            See --startuptime to find out if affects you.
            Only makes a difference on Unix or VMS, when compiled with the
            +X11 feature.  Otherwise it's ignored.
            To disable the connection only for specific terminals, see the
            'clipboard' option.
            When the X11 Session Management Protocol (XSMP) handler has
            been built in, the -X option also disables that connection as
            it, too, may have undesirable delays.

剪贴板选项可用于通过vimrc文件更永久地实现相同的功能。来自:help 'clipboard'

  

永远不要连接到X服务器使用:          排除:。*   这与使用-X参数具有相同的效果。   请注意,当没有与X服务器的连接时   窗口标题将不会恢复和剪贴板   无法访问。

如果您希望Vim在某些情况下连接到X服务器,则可以将clipboard=exclude:.*选项细化为仅适用于特定终端。有关详情,请查看:help 'clipboard'

对我来说,这个问题正在发生,因为我在ssh客户端上启用了“X11 Forwarding”,但并没有在ssh客户端计算机上运行X Server。

当我在目标机器上运行X服务器时,Vim的启动速度要快得多(虽然仍然有点慢)。

在此设置中,我想维护X11 Forwarding,但不需要Vim使用X剪贴板,所以我将set clipboard=exclude:.*行添加到我的vimrc中。现在Vim再次启动对我来说很快。

inits 3

您似乎已经通过尝试vim -u NONE(并且您说您的vimrc为空)来消除您的插件/自定义可能的原因。

我对此问题并不熟悉,但如上所述,可能与您的viminfo文件有关。

您可以使用以下命令启动Vim来确定是否是这种情况:

$ vim -i NONE

根据:help slow-start

  

如果启用了“viminfo”,则加载viminfo文件可能需要一个   而。您可以通过禁用viminfo来查明是否存在此问题   时刻(使用Vim参数“-i NONE”)。尝试减少数量   存储在寄存器中的行“:set viminfo = '20,&lt; 50,s10”。

答案 1 :(得分:0)

我正在使用v7.4。用+ clipboard编译vim时,-X选项成功增加了启动时间。但是,由于现在与X的连接已禁用,因此我们无法再从x剪贴板复制和粘贴。

同时,在发送到电子邮件,推特,电报等之前,vim是我唯一的编写方法。因此,必须从vim复制+粘贴。刚刚找到了简单的解决方案:

alias v='nvim'

Nvim自动使用我以前的.vimrc。剪贴板功能可以无缝工作,而无需任何配置麻烦。

我不鼓励使用nvim。我刚刚发现它是解决我的问题的最快捷的方法。