Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim takes a very long time to start up

Tags:

vim

I'm experiencing a very sluggish startup time with vim as well as other unrelated programs ever since I logged out and logged back in the last time. Following is the startuptime log for 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 ---

Apparently the biggest components are "inits 3" and "setup clipboard".

Any clues what to do about it?

like image 229
Haitham Gad Avatar asked Jan 31 '13 21:01

Haitham Gad


2 Answers

setup clipboard

First, try running Vim with the following command:

$ vim -X

You can try using the -X --startuptime <file> options together to see if the "setup clipboard" component is still slow.

If -X helps, you can get the same effect by adding the following line to your vimrc file:

set clipboard=exclude:.*

Explanation

If this helps what is happening is that on startup Vim is trying to connect to an X server to allow it to use the clipboard. The -X option tells Vim to not try connecting to the X server. From :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.

The clipboard option can be used to achieve the same thing more permanently via your vimrc file. From :help 'clipboard'

To never connect to the X server use: exclude:.* This has the same effect as using the -X argument. Note that when there is no connection to the X server the window title won't be restored and the clipboard cannot be accessed.

The clipboard=exclude:.* option can be refined to only work with particular terminals, if you want Vim to connect to the X server in some instances. Check out :help 'clipboard' for more on this.

For me, this problem was happening because I had "X11 Forwarding" enabled on my ssh client but did not always have an X Server running on the ssh client machine.

When I have an X server running on the target machine, Vim is much faster starting up (though still a bit slow).

In this setup, I want to maintain the X11 Forwarding, but do not need Vim to use the X clipboard, so I added the set clipboard=exclude:.* line to my vimrc. Now Vim startup is quick for me once more.

inits 3

You seem to have already eliminated your plugins/customisations as a possible cause by trying vim -u NONE (and you said your vimrc was empty).

I am not familiar with this issue, but as suggested above, it might be to do with your viminfo file.

You can determine whether this is the case by starting Vim with the following command:

$ vim -i NONE

According to :help slow-start:

If you have "viminfo" enabled, the loading of the viminfo file may take a while. You can find out if this is the problem by disabling viminfo for a moment (use the Vim argument "-i NONE"). Try reducing the number of lines stored in a register with ":set viminfo='20,<50,s10".

like image 91
Paddy O'Loughlin Avatar answered Oct 05 '22 23:10

Paddy O'Loughlin


I'm using v7.4. The -X option increase the startup time successfuly when vim compiled with +clipboard. But, since the connection to the X now disabled, we can't copy and paste from x clipboard anymore.

Meanwhile, vim is my only way to write before send it to email, twitter, telegram, etc. So copy+paste from vim is a must. Just found the simple solution :

alias v='nvim'

Nvim use my old .vimrc automatically. clipboard feature work seamlessly without any configuration hassle.

Not provoking to using nvim. I just found it the shortest solution to my problem now.

like image 39
Brain90 Avatar answered Oct 06 '22 01:10

Brain90