在 Vim 中,运行命令并将标准输出重定向到特定缓冲区

Geo*_*tov 3 vim

假设我并排打开两个缓冲区并将源代码输入缓冲区 1。我想运行编译器(或任何命令行程序)并stdout在缓冲区 2 中查看其输出 ( )。

我如何为stdin这个命令行程序提供当前或特定的缓冲区?如果这是不可能的,我可以将源代码保存到文件中并将其指定为编译器的参数;但无论如何我想在缓冲区 2 中看到输出。

dz9*_*902 5

您可以用来:r! command执行 shell 命令并将其输出读取到当前缓冲区。


mur*_*uru 5

如果你看: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.
Run Code Online (Sandbox Code Playgroud)

而对于+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.
Run Code Online (Sandbox Code Playgroud)

所以:

:2b +r!date
Run Code Online (Sandbox Code Playgroud)

将打开缓冲区 2,并读入date命令的输出。