5

Given two buffers side by side, with the source code in buffer 1, how do I to run the compiler (or any command line program) and see its output (stdout) in buffer 2?

Also, how do I use the current or specified buffer as stdin to this command line program?

3
  • 1
    Look at quickrun plugin Commented Apr 16, 2016 at 13:37
  • 1
    What do you plan to do with the stdout? Do you know about :help :make and :help quickfix? Commented Apr 16, 2016 at 14:49
  • @romainl I didn't know quickfix plugin, that's probably what I need. Thanks. Commented Apr 16, 2016 at 15:00

2 Answers 2

6

You can use :r! command to execute shell command and read its output to current buffer.

Sign up to request clarification or add additional context in comments.

Comments

5

If you look at :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.

And for +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.

So:

:2b +r!date

Would open buffer 2, and read in the output of the date command.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.