1

I'm trying to debug an error in a vim plugin. The only clue I'm getting regarding the location of the error is this message:

Error detected while processing function 190[2]..191[15]..218:
line   27:
<custom error message>

I've tried Googling an answer to this question, but it hasn't turned up anything. I know that:

  • [2], [15], and 27 are line number offsets from the function definition, and
  • 190, 191, and 218 point to functions.

I don't need help debugging the script, but I'd like to know how to find the names of these functions? Is there a built-in Vim function to reveal the functions' number/name association?

2 Answers 2

1

I use fnum to represent function number in this answer.

Get numbered function definition

:function {fnum}

It's documented at :h numbered-function

Add breakpoint to numbered-function

:breakadd func lnum fnum

Note that everytime you sourced a numbered function, a new numbered function is created.

Add breakpoint to numbered-function without knowing the number

It's the same job as get number of numbered-function from definition, it's dirty and crude, you properbally don't want to do it.

You can loop function number from 1 to a max number and compare result of function {fnum} and your current numbered function. There will be multiple results if numbered function is sourced multiple times.

Set breakpoint to all numberd-funcitons

:breakadd func lnum [0-9]\\\{1,\}

:h :debug-name use the same pattern with autocommand, it's documented at :h file-pattern .

Update

:verbose function {fnum} will also tell you where the function is defined (Thanks to Phi R).

5
  • 1
    Tpope’s scriptease is also good for this, providing a souped up Breakadd as well as other goodies
    – D. Ben Knoble
    Jun 11, 2019 at 0:45
  • @D.BenKnoble It doesn't support numbered function.
    – dedowsdi
    Jun 11, 2019 at 1:13
  • This is exactly what I was looking for. Thanks!
    – Phil R
    Jun 11, 2019 at 15:02
  • 1
    While it doesn't give you the name of the function, :verbose function {42} will show you where the function is defined.
    – Phil R
    Jun 11, 2019 at 15:09
  • @PhilR That's something i'm looking for, thanks.
    – dedowsdi
    Jun 11, 2019 at 23:03
0

If you are profiling when the function is called, vim will print the lines of the function to a log file.

:profile foo.log
:profile func *

{do whatever causes the error}

:profile pause
:noautocmd qall!

Now, inspect foo.log for lines like /FUNCTION\s\+190(/. The location (script/linenumber) where the function is defined will be printed.

1
  • Thanks for the suggestion; however, I should've mentioned my error is thrown by an VimEnter autocommand, so I couldn't get profiling to work.
    – Phil R
    Jun 11, 2019 at 15:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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