Neovim 的作业控制示例:help job-control
适用于 bash 脚本。但是,我无法使其适用于红宝石。考虑以下示例:
set nocp
set buftype=nowrite
call jobstart('shell', 'bash', ['-c', 'for ((i = 0; i < 5; i++)); do sleep 2 && printf "Hello Bash!\n"; done'])
call jobstart('shell', 'ruby', ['-e', '5.times do sleep 2 and puts "Hello Ruby!" end'])
function JobHandler()
if v:job_data[1] == 'exit'
let str = v:job_data[0] . ' exited'
else
let str = join(v:job_data[2])
endif
call append(line('$'), str)
endfunction
au JobActivity shell* call JobHandler()
运行nvim -u NONE -S <filename>
产生以下输出:
Hello Bash!
Hello Bash!
Hello Bash!
Hello Bash!
Hello Bash!
1 exited
Hello Ruby! Hello Ruby! Hello Ruby! Hello Ruby! Hello Ruby!
2 exited
我们如何使 ruby 示例像 bash 那样工作?