I want to create a lua command where you give it a lua function, and it executes the function and then writes the function’s output to the current buffer at the current cursor position
I’ve tried something like this
function please_redirect_my_output()
print('hello world') -- some output to redirect
end
function redirect_f(f)
vim.fn.execute('redir @">')
f()
vim.fn.execute('redir END')
end
and then I do lua redirect_f(please_redirect_my_output)
but that doesn’t work. what am I missing? what don’t I understand about redir
and execute
?