Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can I get last echoed message in vimscript?

Tags:

vim

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!

like image 713
Dmitry Ermolov Avatar asked Mar 26 '11 10:03

Dmitry Ermolov


1 Answers

You can't retrieve last echoed message. But there are other options:

  1. 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, "")
    
  2. 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, "")
    
like image 125
ZyX Avatar answered Sep 21 '22 12:09

ZyX