tags:

views:

378

answers:

4

I've got alot of plugins enabled when using vim which I've collected over the years. I'm a bit fed up with how long vim takes to start now so I'd like to profile it's startup and see which of the many plugins I have are responsible. Is there anyway to profile vim startup or script running? Ideally I'd like to know how long vim spent in each vim script it loads.

+2  A: 

If you're loading your plugins from a .vimrc file, what you could do is put a q on some line part way through the file to make it quit so you can use a process timer, like the unix time command. More thoroughly, this would look like:

  1. backup existing .vimrc file
  2. comment out all but a select number of plugins
  3. insert a q line
  4. call time vim repeteadly and average
  5. restore backup

This is not elegant but I think it will get the job done.

David Berger
Hmm, not bad in a pinch. I've already got my vimrc split into lots of seperate files so shouldn't be too hard to automate.
Benj
+12  A: 

You could run vim -V, pipe the output through a utility that adds timestamps and analyze the output. This command lines does this, e.g.:

vim -V 2>&1 | perl -MTime::HiRes=time -ne 'print time, ": ", $_' | tee vilog

You might have to blindly type :q to get back to your prompt. Afterwards, you should find the file vilog in your current directory with hires timestamps at the beginning of each line.

If you can do with a granularity of a second, you can do this:

vim -V 2>&1 | perl -ne 'print time, ": ", $_' | tee vilog
innaM
Fantastic, what a great solution.
Benj
Did you know the "perl -n" does the while (<>) {} for you.
Benj
Now that you mention it: yes, I did. I'm going to edit the answer to get shorter commands. Thanks.
innaM
+4  A: 

I refined the vim -V solution by Manni to show the delta time:

vim -V 2>&1 | perl -MTime::HiRes=time -ne '$a = time unless defined $a; print time - $a, ": ", $_' | tee vilog
Benj
Sweet! I took the liberty to shorten this a bit and make it more "Perlish".
innaM
Cheers Manni, Good call ;-)
Benj
+7  A: 

If you're using Vim 7.2.269 or later, then there's the --startuptime option you can use.

vim --startuptime=vim.log
jamessan
And as of patch 7.2.286, there's no equal sign needed. "vim --startuptime vim.log"
jamessan