You cannot receive the last echo message. But there are other options:
If you can put the :redir before calling this function, and then another one, you can catch everything that it repeats. But keep in mind that redirects are not nested, so if a function uses :redir , you will not get anything:
redir => s:messages echo "foo" redir END let s:lastmsg=get(split(s:messages, "\n"), -1, "")
If the function uses :echomsg instead of :echo , you can use the command :messages and :redir :
echom "foo" redir => s:messages messages redir END let s:lastmsg=get(split(s:messages, "\n"), -1, "")
source share