How do I execute a shell command and return the results to VIM

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

How do I execute a shell command and return the results to VIM

Boyd, Craig
I am using VIM 6.1 on Windows and I would like run a script and have the
results returned to a new instance of VIM.
For instance "DIR /S" and return the produced list to VIM.

It does not have to be a script, per se, so whatever VIM functionality is
best.  I am still a newbie at this.

Thanks,

Craig Boyd
> "A lie can travel halfway around the world while the truth is putting on
> its shoes. " ~ Mark Twain
>
>
Reply | Threaded
Open this post in threaded view
|

Re: How do I execute a shell command and return the results to VIM

Stephen R Laniel
On Tue, Aug 09, 2005 at 02:19:30PM -0500, Boyd, Craig wrote:
> I am using VIM 6.1 on Windows and I would like run a script and have the
> results returned to a new instance of VIM.
> For instance "DIR /S" and return the produced list to VIM.
>
> It does not have to be a script, per se, so whatever VIM functionality is
> best.  I am still a newbie at this.

I've never used vim under Windows, but if it's at all like
vim under Linux you'll just do

:r !dir /s

within command mode (rather than edit mode). Thie will read
('r') the results of the shell command ('!') dir /s.

Let us know if that helps.

--
Stephen R. Laniel
[hidden email]
+(617) 308-5571
http://laniels.org/
PGP key: http://laniels.org/slaniel.key

signature.asc (196 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: How do I execute a shell command and return the results to VIM

Tim Chase-2
In reply to this post by Boyd, Craig
> For instance "DIR /S" and return the produced list to VIM.

It depends on whether you want to launch a new copy of vim, or
read the results into an existing copy of vim.

To read the results into a new copy of vim,

        dir /s | vim -

(the minus sign means "read from standard-in")

If you already have an open copy of vim, and want to read in the
results of a script/command, you can use

        :r! dir /s

from within vim.  This reads the results in below the current
line.  If you want to read them *above* the current line, use

        :-r! dir /s

or if you want to read them in as the very first line, you can use

        :0r! dir /s

For more info, see

        :help --
        :help :r!

Hope this helps,

-tim





Reply | Threaded
Open this post in threaded view
|

Re: How do I execute a shell command and return the results to VIM

A.J.Mechelynck
In reply to this post by Boyd, Craig
----- Original Message -----
From: "Boyd, Craig" <[hidden email]>
To: <[hidden email]>
Sent: Tuesday, August 09, 2005 9:19 PM
Subject: How do I execute a shell command and return the results to VIM


>I am using VIM 6.1 on Windows and I would like run a script and have the
> results returned to a new instance of VIM.
> For instance "DIR /S" and return the produced list to VIM.
>
> It does not have to be a script, per se, so whatever VIM functionality is
> best.  I am still a newbie at this.
>
> Thanks,
>
> Craig Boyd
>> "A lie can travel halfway around the world while the truth is putting on
>> its shoes. " ~ Mark Twain
>>
>>
>
>

    :[range]r !command

[range] is the line number (in the current buffer) determining where the
SYSOUT output of the command will be pasted (apparently before a single line
# or after the second of two line numbers, but I'm not 100% certain, more
experimenting might be needed). Use :$r to paste after the last line, or :0r
(zero) to paste before the first line. Default (no line number) is current
line (the line your cursor is on).

For instance, to add to the end of the current buffer the list (with
details, and sorted by name) of all *.vim files in the current directory,
use

(on Windows)
    :$r !dir /o:n *.vim
or (on Unix)
    :$r !ls -l *.vim

HTH,
Tony.