Debugging Vim plugins with call traces

Darek picture Darek · Mar 11, 2012 · Viewed 11.2k times · Source

What is the preferable, general method of debugging/tracing vim plugins ? Suppose I have got a fairly sophisticated plugin Foo, which on a key pressed F9 opens new window with file-browser and gives the possibility to choose a file, after that the filename is copied into the main window. I would like to see what is called when I press the F9 key, some kind of call trace.

Answer

Prince Goulash picture Prince Goulash · Mar 12, 2012

The best way I have found is to use the -V flag when starting (g)vim. You can specify a level of tracing N and a filename for the written log:

$ vim -V[N]{filename}

Then trace messages will be given for each file that is sourced. (See :help -V for more info.)

Trawling through the resulting logfile can be painful, but it is usually pretty informative. I find it best to view the logfile before and after the trigger event (pressing <F9> in your case) to get a picture of when is happening.