vim:如何将 shell 命令“:!echo foo”的输出重定向到缓冲区?

问题描述 投票:0回答:2

给定两个并排的缓冲区,源代码位于缓冲区 1 中,如何运行编译器(或任何命令行程序)并在缓冲区 2 中查看其输出 (

stdout
)?

另外,如何使用当前或指定的缓冲区作为此命令行程序的

stdin

vim
2个回答
5
投票

您可以使用

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


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.

对于

+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
命令的输出。

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.