I am apparently not getting a return value from execute():
function! Example()
return 5
endfunction
:echo execute("call Example()")
Just results in a blank line. The 5 is not printed. Why is this?
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.
Sign up to join this communityFrom the documentation of execute
, i.e. :h execute()
:
execute({command} [, {silent}])
Execute{command}
and capture its output.
If{command}
is a String, returns{command}
output.
If{command}
is a List, returns concatenated outputs.
execute()
returns the output of whatever is executed, not the return value of any function that may (or may not) be executed.
As an example,
echo execute('echo "test"')
will echo "test", while
echo execute('call SomeFunc(...)')
will only output whatever is echoed inside the function SomeFunc
. The return value is not relevant here.
this is because call Example()
alone wouldn't print anything.
You need :echo execute("echo Example()")
for execute() to print anything.
If your goal is just to print the return value of the function, you don't need the execute
or the call
:
:echo Example()