簡體   English   中英

在Vim中,運行命令並將stdout重定向到特定緩沖區

[英]In Vim, run command and redirect stdout to specific buffer

假設我並排打開兩個緩沖區,並將源代碼輸入緩沖區1。我想運行編譯器(或任何命令行程序),並在緩沖區2中查看其輸出( stdout )。

如何將當前或特定緩沖區作為stdin送入此命令行程序? 如果不可能,我可以將源代碼保存到文件中,並指定它作為編譯器的參數; 但無論如何,我想在緩沖區2中看到輸出。

如果您看:h :b

:[N]b[uffer][!] [+cmd] [N]              :b :bu :buf :buffer E86
                Edit buffer [N] from the buffer list.  If [N] is not given,
                the current buffer remains being edited.  See :buffer-! for
                [!].  This will also edit a buffer that is not in the buffer
                list, without setting the 'buflisted' flag.
                Also see +cmd.

對於+cmd

                                                        +cmd [+cmd]
The [+cmd] argument can be used to position the cursor in the newly opened
file, or execute any other command:
        +               Start at the last line.
        +{num}          Start at line {num}.
        +/{pat}         Start at first line containing {pat}.
        +{command}      Execute {command} after opening the new file.
                        {command} is any Ex command.

所以:

:2b +r!date

將打開緩沖區2,並讀入date命令的輸出。

您可以使用:r! command :r! command執行shell命令並將其輸出讀取到當前緩沖區。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM