Let's say I do a simple shell command like ls. Is there some way to directly pipe the output into a new vim buffer, so that I could edit it in place or just have a look at it.

Basically like less + the ability to edit it and directly save it in some place on the system?


2 Answers 2


You can do this from directly inside of vim with the :read command, which is abbreviated to :r The 'read' command is intended to allow you to read a file, e.g.

:r foo.txt

Will insert the contents of foo.txt after your current cursor position.

From :help :r

                            *:r* *:re* *:read*
:r[ead] [++opt] [name]
            Insert the file [name] (default: current file) below
            the cursor.
            See |++opt| for the possible values of [++opt].

However, you can read a command that outputs to STOUT just as if it was a file. To call the external command, just prepend an exclamation mark. This gives us:

:r !ls

You can also do this from the terminal before you start vim by using pipes. For example

ls | vim

However, you must explicitly tell vim to read from STDIN, which can by starting vim with a - at the end.

ls | vim -

From :help --`

-       This argument can mean two things, depending on whether Ex
        mode is to be used.

        Starting in Normal mode: >
            vim -
            ex -v -
        Start editing a new buffer, which is filled with text
        that is read from stdin.  The commands that would normally be
        read from stdin will now be read from stderr.  Example: >

If you want to just get the input from a terminal command, then just do the following

ls | vim -

Same for any other command output you want to pipe to Vim. If you want to read the output you can use read or r as already mentioned. You can also use the dot (.) to do the same. So doing this,

: . !ls 

will give the same result as using read. Similarly for inserting date,

: . !date

Not the answer you're looking for? Browse other questions tagged or ask your own question.