echo - In vim, how do I redirect the output of a vimscript function? -
i have vimscript function
function! env() redir => s sil! exe "norm!:ec$\<c-a>'\<c-b>\<right>\<right>\<del>'\<cr>" redir end return split(s) endfunction this function obtained question:
how list environment variables in vim?
when :call env() don't see output, :echo env() displays output names of environment variables.
i'd rather copy , paste output somehow. know :redir. doesn't work:
:redir @a :echo env() :redir end "ap instead, blank line pasted.
i have tried many combinations of :redir command (to registers and/or files) , variations on call env() without success. because output generated calling function? thought might because function returns list, :echo string(env()) isn't captured :redir either.
edit: modified solution used answer below.
function! env() redir => s sil! exe "norm!:ec$\<c-a>'\<c-b>\<right>\<right>\<del>'\<cr>" redir end let @s = string(split(s)) endfunction one can execute :call env() , "sp paste.
related question:
how redirect ex command output current buffer or file?
as said in comment, problem :redir that's being discussed on vim_dev. in short, nested redirection :redir isn't possible.
but of course can modify env() function redirect output register or global variable.
just change redir => s either redir => g:s (global variable g:s) or redir @s (register s), , remove return statement. let's use register:
function! env() redir @s sil! exe "norm!:ec$\<c-a>'\<c-b>\<right>\<right>\<del>'\<cr>" redir end endfunction after calling function, output stored in register s , can put "sp, of course.
Comments
Post a Comment