0

I am trying to create a command that calls the same function but with different arguments, like the following:

def g:MyFunction(a: string, b: bool)
    if b
        echo "foo"
    else
        echo "bar"
    endif
enddef


command! -nargs=+ -complete=command MyCommand0 silent call MyFunction(<f-args>, false)
command! -nargs=+ -complete=command MyCommand1 silent call MyFunction(<f-args>, true)

But I get no output. I think the problem resides in how I define the commands but I don't know how to fix it. I read here but it didn't really help.

1 Answer 1

1

You are prefixing your function call with silent which effectively suppresses output of your echo in the function.

Remove it and see different output.

vim9script

def g:MyFunction(a: string, b: bool)
    if b
        echo "foo"
    else
        echo "bar"
    endif
enddef

command! -nargs=+ -complete=command MyCommand0 call MyFunction(<f-args>, false)
command! -nargs=+ -complete=command MyCommand1 call MyFunction(<f-args>, true)
1
  • Auch! My bad! Thanks!
    – Barzi2001
    Commented Mar 11, 2023 at 11:10

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.