如何重复使用相同的Vim窗口/缓冲区进行命令输出,例如:help窗口?

时间:2011-03-14 19:26:02

标签: vim

虽然我不是Vim专家,但我一直在努力研究TextMate的⌘R功能a rough Vim equivalent来从缓冲区运行Ruby代码并显示输出。

脚本当前只是用:new打开一个新窗口(拆分)并将输出放在那里。如果多次运行它,它会打开多个窗口。理想情况下,我希望在每个标签页中重复使用相同的窗口,就像:help一样。

我看过,但还没有找到实现这个目标的方法。有什么指针吗?

3 个答案:

答案 0 :(得分:6)

您可以使用名称创建临时缓冲区,以便在后续调用中可以检查该缓冲区是否已打开(如果已重用),或者您需要一个新缓冲区。像这样:

function! Output()
    let winnr = bufwinnr('^_output$')
    if ( winnr >= 0 )
        execute winnr . 'wincmd w'
        execute 'normal ggdG'
    else
        new _output
        setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile nowrap
    endif
    silent! r! ls
endfunction

答案 1 :(得分:0)

我想你可以手动完成。

例如:

:e test1.txt   (or use any existing buffer)
:vs            (or :new or :sp)
:b <tab>       (keep pressing tab until test1.txt comes up. or use the buff no)

答案 2 :(得分:0)

您可能希望使用quickfix窗口,以便跳转到错误。如果您获得ruby compiler vim plugin,则可以运行:make来运行代码。您应该在quickfix(:copen)中看到输出和错误。