vim - 如何将 `RustRun`重定向到Vim中的拆分缓冲区

标签 vim rust vim-plugin neovim

在带有rust.vim的vim中运行RustRun时,它将输出其输出到vim命令输出控制台。而为Go程序运行go-run,它将打开一个新的终端拆分并在其中打印输出。

  • 如何在新的分割缓冲区中运行Rust程序?
  • 每次调用rust运行时,如何重用相同的缓冲区?
  • 最佳答案

    为此,我使用了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/

    相关文章:

    Vim Supertab 插件在导航完成菜单时反转方向

    integer - 如何让 Vim 测试用户输入是否为整数?

    vim - 从剪贴板粘贴并自动切换“:set paste”

    reference - 引用的身份关闭

    vim:在新选项卡中打开标签

    vim缩进: align function arguments

    vim - vim 中 "selection mode"的常见用例是什么?

    vim - Vim 中无法反转 Ctrl-O

    rust - 可转换为 isize 的枚举的特征

    rust - 为什么我不能在模式匹配时使用常量,即使它实现了 PartialEq 和 Eq?