给定两个并排的缓冲区,源代码位于缓冲区 1 中,如何运行编译器(或任何命令行程序)并在缓冲区 2 中查看其输出 (
stdout
)?
另外,如何使用当前或指定的缓冲区作为此命令行程序的
stdin
?
您可以使用
:r! command
执行 shell 命令并将其输出读取到当前缓冲区。
: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
命令的输出。