0

I've learnt how to put variable value to file with this Stackoverflow link.

e.g. :let L = [1,2,3] :put string(L)

[1, 2, 3]

It seems the method mentioned in above link is dealing with the return value of an expression.
But, how to catch the content echoed by echo command? Which I suppose is how function FunctionName works, echo the content of a function to the screen.
As the echoed content shown in my vim interface, wouldn't they go to some register, or other kind of buffer?
Is it able to catch these echoed content and redirect them to file in vim?

0

A solution figured out by myself:

:function Echo_to_file(expr_str)
:    redir => zen_temp | exe a:expr_str | redir END | put=zen_temp
:endfunction


:call Echo_to_file("function Echo_to_file")

   function Echo_to_file(expr_str)
1      redir => zen_temp | exe a:expr_str | redir END | put=zen_temp
   endfunction

It works pretty good, though I don't know why there is a weird 1 in the result.

  • 2
    That's line number in your function body. – cuonglm Aug 15 '15 at 6:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.