在带有rust.vim的vim中运行RustRun时,它将输出其输出到vim命令输出控制台。而为Go程序运行go-run
,它将打开一个新的终端拆分并在其中打印输出。
最佳答案
为此,我使用了Redir
将命令输出重定向到新的拆分窗口。
要重用相同的缓冲区,请创建一个新的命名缓冲区,然后将输出写入其中。调用rust run时,找到命名的缓冲区并删除(如果存在)。
function! Redir(cmd)
redir => output
silent! execute(a:cmd )
redir END
let output = split(output, "\n")
if bufwinnr('rust.out') >0
bdelete rust.out
endif
vnew rust.out
let w:scratch = 1
setlocal buftype=nofile filetype=rust_out bufhidden=wipe noswapfile
call setline(1, output)
"focus back to the source file on the left, from which we ran `RustRun`
wincmd h
endfunction
"redirect any vim command output using Redir command.
command! -nargs=1 Redir call Redir(<f-args>)
"mapping for rust files.
au FileType rust nmap <silent> <leader>rr :call Redir('RustRun')<CR><CR>
关于vim - 如何将 `RustRun`重定向到Vim中的拆分缓冲区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65335637/