Is there any way to retrieve last echoed message into a variable?
For example: if i call function, that does:
echo 'foo'
Can I somehow retrieve this 'foo' into a variable?
Thanks!
You can't retrieve last echoed message. But there are other options:
If you can place a :redir
command before this function call and another one after, you can catch everything it echoes. But be aware that redirections do not nest, so if function uses :redir
itself, you may get nothing:
redir => s:messages
echo "foo"
redir END
let s:lastmsg=get(split(s:messages, "\n"), -1, "")
If function uses :echomsg
instead of :echo
, then you can use :messages
command and :redir
:
echom "foo"
redir => s:messages
messages
redir END
let s:lastmsg=get(split(s:messages, "\n"), -1, "")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With