vim takes a very long time to start up

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.


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".

Tags:

Vim