23

In some occasions, Vim respond is very slow. Is there a procedure to easily identify what causes the problem?

6
  • Have you installed any plugins?
    – Melon
    Feb 4 '15 at 9:00
  • Something akin to bash -x to see what gets executed would be useful.
    – muru
    Feb 4 '15 at 9:00
  • @Melon: Yes I only have 1 plugin installed. muru: Can you explain further?
    – Demetris
    Feb 4 '15 at 9:04
  • 1
    Dangit, I answered a duplicate. While I vote to close this as a duplicate, I also respond to your comment: LatexBox shouldn't be called 2000 times after deleting 2 words. Now that you've found the problem, you have to finagle with the plugin. I wish I knew more about LatexBox to help you. Feb 4 '15 at 9:20
  • 1
    @Carpetsmoker Yes, this answer is very close to what I had in mind for this question.
    – muru
    Feb 4 '15 at 9:23
40

Vim has a built-in profile set of commands. See :h profile.

You would open up vim, and then run the following

:profile start profile.log

This sets up the file profile.log to be the log file. If it already exists, it will be overwritten. We now need to tell vim what to profile

:profile func *
:profile file *

This says to profile all functions and all script files. Overkill, perhaps. Now, you should do things that make vim act slowly. They are being profiled in the background. Once you have concluded, end the profiling.

:profile pause

And quit vim. Now, read the profile.log file and see what's slow. Note that this is for slow running inside of vim. If vim is slow to start up (a different problem), you should start vim with

vim --startuptime log.txt

and read the times, see what's taking so long.

4
  • I followed your instructions. After starting profiling, I used dw twice and then exit. Then looking at the log I got FUNCTION LatexBox_FoldLevel(), Called 1930 times
    – Demetris
    Feb 4 '15 at 9:16
  • When I try this I get "E319: Sorry, the command is not available in this version" Mar 15 '19 at 15:31
  • @BarryMcNamara You can see more about this in :h profile. Using profile requires vim to be compiled with +profile, which happens to be true for many (but not all) vim binaries provided on distributions. You might try compiling your own vim, or installing a more featurefull binary. Mar 16 '19 at 0:35
  • I'm using the default Mac one, and it seems that I have the normal version whereas profile is only included in the huge version. However, I managed to fix the closing lag I was experiencing by renaming my .vimrc to something else and then renaming it back. Mar 17 '19 at 1:16

Not the answer you're looking for? Browse other questions tagged or ask your own question.