0

On Windows 10, using gvim, when editing a file like the following example:

foo
foobar
baz

As long as I use a function and not a def, I can do the following and Cfilter will work as expected:

:function! MyQuickFixTextFunc(lines)
:  return ['']
:endfunction

:set quickfixtextfunc=MyQuickFixTextFunc
:vim /foo/ %
:packadd cfilter
:Cfilter bar

However, when using vim9script's def, the following Cfilter will display E117: Unknown function: MyQuickFixTextFunc

:def MyQuickFixTextFunc(info: dict<number>): list<string>
:  return ['']
:enddef
:defcompile MyQuickFixTextFunc

:set quickfixtextfunc=MyQuickFixTextFunc
:vim /foo/ %
:packadd cfilter
:Cfilter bar

Is there something I'm doing wrong in my attempt to apply MyQuickFixTextFunc when using a function defined using vim9script syntax?

1 Answer 1

1

The function created by "def" is script-local by default. On the other hand, the function created by "function" is global by default. The 'quickfixtextfunc' option should be set to a global function. You can prefix the function name with "g:" when defining the function using "def". Also, you don't need to explicitly call the ":defcompile" command to compile the function.

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.