In Vim, you can sink the output, for example. "w! ruby" to the buffer line by line, since they are output?

I am currently doing something like this:

redir => m
  silent w ! ruby
redir END
new
put=m

It executes the contents of the current buffer as Ruby code and puts the output in a new buffer.

But if the Ruby code I run is similar to

puts "start"
sleep 10
puts "end"

then I won’t see the exit for 10 seconds, then both "start" and "end" all at once.

Is there any way to stream the output to the buffer, in turn, how does it appear? So that I see the "beginning", after 10 seconds I will see the "end"? Like what happens if I just do

w ! ruby

and look at the output on the command line.

+3
source share
3 answers

Vim -, .

Python subprocess (Ruby , . if_ruby):

python << EOF
import vim
import subprocess

def output_lines_to_buffer(cmd):
    """
    Append the given shell command output linewise to the current buffer.
    """
    p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
    for line in iter(p.stdout.readline, ''):
        vim.current.buffer.append(line)
        vim.command('redraw')
EOF

:

:python output_lines_to_buffer('my command')

, my command . , .., , .

+2

, (, ) - , :setlocal autoread, .

. Tail Bundle.vim, , .

.

0

tee :make, tee.

let fname = tempname()
exec "w ! ruby 2>&1 | tee ".fname
exec "new ".fname

Edit: It looks like you are running Linux or an operating system that creates 4K buffers between pipelines. To get around this, install expect( sudo apt-get install expect-dev) and use the command unbufferto enable streaming in turn (see https://stackoverflow.com/questions/1000674/turn-off-buffering-in-pipe ).

let fname = tempname()
exec "! unbuffer ruby % 2>&1 | tee ".fname
exec "new ".fname
0
source

All Articles