How can I get the last echo message in vimscript?

Is there a way to get the last echo message in a variable?
For example: if I call a function, it does:

echo 'foo' 

Is there any way to restore this "foo" in a variable?
Thanks!

+4
source share
1 answer

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, "") 
+9
source

Source: https://habr.com/ru/post/1345324/


All Articles