RE: How do I execute a shell command and return the results to VI M

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

RE: How do I execute a shell command and return the results to VI M

Boyd, Craig
This loads the listing into the existing file I am editing.  I would like
the listing loaded into a new instance (buffer?) of VIM.

Aside from that, it is pretty slick!

Thanks,

Craig

-----Original Message-----
From: Stephen R Laniel [mailto:[hidden email]]
Sent: Tuesday, August 09, 2005 2:23 PM
To: Boyd, Craig
Cc: '[hidden email]'
Subject: Re: How do I execute a shell command and return the results to
VIM


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
Reply | Threaded
Open this post in threaded view
|

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

John (Eljay) Love-Jensen
Hi Craig,

> This loads the listing into the existing file I am editing.  I would like
> the listing loaded into a new instance (buffer?) of VIM.

Do this...

:vsplit
:arga new.txt
:n
:r!dir /s

If this is something you do a lot, you can bind it to a key combination or a
make a function of it (or both), for your convenience.

You may prefer :split (horizontal) over :vsplit (vertical).

Voila!
--Eljay


Reply | Threaded
Open this post in threaded view
|

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

Aaron Griffin
Ya know, the netrw plugin supports this out of the box, and actually
allows you do things with it.  At least with 6.3, netrw comes
standard.

Try
:sb
:e c:\program\ files

and you get a nice listing of that directory which also allows you to
hit enter on an entry to open it
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: "'Stephen R Laniel'" <[hidden email]>
Cc: <[hidden email]>
Sent: Tuesday, August 09, 2005 9:27 PM
Subject: RE: How do I execute a shell command and return the results to VIM


> This loads the listing into the existing file I am editing.  I would like
> the listing loaded into a new instance (buffer?) of VIM.
>
> Aside from that, it is pretty slick!
>
> Thanks,
>
> Craig

To read it into a new buffer, just open an empty buffer first.

To clear the current window, as with the File -> New menu:

    :enew

(or :enew! to abandon any possible changes).

To open a new window on an empty buffer:

    :new

So, to read the full recursive directory of your whole C disk into an empty
buffer in a new window:

    :new
    :0r !dir /S C:\


HTH,
Tony.


Reply | Threaded
Open this post in threaded view
|

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

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


> Ya know, the netrw plugin supports this out of the box, and actually
> allows you do things with it.  At least with 6.3, netrw comes
> standard.
>
> Try
> :sb
> :e c:\program\ files
>
> and you get a nice listing of that directory which also allows you to
> hit enter on an entry to open it
>
>
>
>
yeah, except he was asking for "dir /s" and that's a single recursive
listing of a directory and all its subdirectories.

Best regards,
Tony.


Reply | Threaded
Open this post in threaded view
|

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

Tim Chase-2
In reply to this post by Boyd, Craig
> This loads the listing into the existing file I am editing.  I
> would like the listing loaded into a new instance (buffer?) of
> VIM.

Clarifying definitions might help (both so you know which of
these solutions are what you want, and to give you the vocabulary
in the future to ask what you mean :)

An "instance" of vim  will show up in your process listing,
launched by clicking a vim icon, or typing "vim" (or "gvim") at a
command prompt.  To load the results of a command in a new
*instance* of vim, use

        dir /s | vim -

A buffer is vim's view of a file.  A single instance of vim can
have multiple buffers open.  There's a fairly 1-to-1 mapping of
files vim has open to buffers (the exception that occurs to me is
that you can have buffers that don't have a file associated with
them, such as the results of ":new").  To read the results of a
script into a new *buffer*, use

        :enew | 0r! dir /s

Just to confuse matters further, vim also has *windows*.  These
are subdivisions of the screen-space.  Multiple windows on the
same buffer can be open at the same time, and changes in one
window are reflected in all the windows on that buffer.  To open
a new *window* and read in the results you want, you can simply use

        :sp | 0r! dir /s

For those last two, they're simply two commands (the "sp" or
"enew" and the command to read the results) so they could be done as

        :enew
        :0r! dir /s

and

        :sp
        :0r! dir /s

-tim




Reply | Threaded
Open this post in threaded view
|

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

Aaron Griffin
In reply to this post by A.J.Mechelynck
On 8/9/05, Tony Mechelynck <[hidden email]> wrote:
> yeah, except he was asking for "dir /s" and that's a single recursive
> listing of a directory and all its subdirectories.

Ah, forgot my windows switches, didn't know \s was recursive...
Reply | Threaded
Open this post in threaded view
|

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

A.J.Mechelynck
In reply to this post by Tim Chase-2

----- Original Message -----
From: "Tim Chase" <[hidden email]>
To: "Boyd, Craig" <[hidden email]>
Cc: <[hidden email]>
Sent: Tuesday, August 09, 2005 9:58 PM
Subject: Re: How do I execute a shell command and return the results to VI M


>> This loads the listing into the existing file I am editing.  I
>> would like the listing loaded into a new instance (buffer?) of
>> VIM.
>
> Clarifying definitions might help (both so you know which of these
> solutions are what you want, and to give you the vocabulary in the future
> to ask what you mean :)
>
> An "instance" of vim  will show up in your process listing, launched by
> clicking a vim icon, or typing "vim" (or "gvim") at a command prompt.  To
> load the results of a command in a new *instance* of vim, use
>
> dir /s | vim -
>
> A buffer is vim's view of a file.  A single instance of vim can have
> multiple buffers open.  There's a fairly 1-to-1 mapping of files vim has
> open to buffers (the exception that occurs to me is that you can have
> buffers that don't have a file associated with them, such as the results
> of ":new").  To read the results of a script into a new *buffer*, use
>
> :enew | 0r! dir /s
>
> Just to confuse matters further, vim also has *windows*.  These are
> subdivisions of the screen-space.  Multiple windows on the same buffer can
> be open at the same time, and changes in one window are reflected in all
> the windows on that buffer.  To open a new *window* and read in the
> results you want, you can simply use
>
> :sp | 0r! dir /s
>
> For those last two, they're simply two commands (the "sp" or "enew" and
> the command to read the results) so they could be done as
>
> :enew
> :0r! dir /s
>
> and
>
> :sp
> :0r! dir /s
>
> -tim
>
>
>
>
>
>

Beware: without an argument, ":split" (or :sp) opens a new window on the
_current_ buffer, and you'll end up clobbering the current file. ":new",
OTOH, opens a new _empty_ window, which in this case is more useful.

Best regards,
Tony.


Reply | Threaded
Open this post in threaded view
|

RE: How do I execute a shell command and return the results to VI M

Boyd, Craig
In reply to this post by Boyd, Craig
I have noticed in almost all of the solutions the DOS windows does not close
and the VIM buffer/window/new instance does not update until that happens.
Any thoughts?

Thanks, all of you have been VERY helpful with this.

Craig

-----Original Message-----
From: Aaron Griffin [mailto:[hidden email]]
Sent: Tuesday, August 09, 2005 2:55 PM
To: [hidden email]
Subject: Re: How do I execute a shell command and return the results to
VI M


On 8/9/05, Tony Mechelynck <[hidden email]> wrote:
> yeah, except he was asking for "dir /s" and that's a single recursive
> listing of a directory and all its subdirectories.

Ah, forgot my windows switches, didn't know \s was recursive...
Reply | Threaded
Open this post in threaded view
|

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

Aaron Griffin
On 8/9/05, Boyd, Craig <[hidden email]> wrote:
> I have noticed in almost all of the solutions the DOS windows does not close
> and the VIM buffer/window/new instance does not update until that happens.
> Any thoughts?
>
> Thanks, all of you have been VERY helpful with this.
>
> Craig

Hrrrm... on the off chance that you're more comfortable with it, you
could try cygwin's rxvt or the terminal which comes with msys... I use
vim (not gvim) from within msys all the time - yeah it's version 5.8
or something.... I've been meaning to build a 7.0 version through
msys, just to see if it works... in fact lemme try now.
Reply | Threaded
Open this post in threaded view
|

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

A.J.Mechelynck
In reply to this post by Boyd, Craig
----- Original Message -----
From: "Boyd, Craig" <[hidden email]>
To: "'Aaron Griffin'" <[hidden email]>; <[hidden email]>
Sent: Tuesday, August 09, 2005 11:04 PM
Subject: RE: How do I execute a shell command and return the results to VI M


>I have noticed in almost all of the solutions the DOS windows does not
>close
> and the VIM buffer/window/new instance does not update until that happens.
> Any thoughts?
[...]

That's normal. Vim can call an external program, even get output from it,
but it's not an interactive shell. Once the program finishes, the dos box
closes and Vim gets access to the program's output. Not before.

If you want to do "other Vim things" in the meantime, run the command in a
separate Dos box with redirected output:

    C:\Documents and Settings\craigboyd\>dir /S >%TEMP%\dirlist.txt

(the part up to and including the first > is a supposed "Dos prompt". You
type only the rest, of course.) When it is finished, read the output in Vim
at your leisure:

    :new $TEMP/dirlist.txt

You can of course give the temp file any name that suits you. %TEMP% is Dos
notation for the environment variable TEMP and $TEMP is Vim (and Unix)
notation for the same.

Best regards,
Tony.


Reply | Threaded
Open this post in threaded view
|

RE: How do I execute a shell command and return the results to VI M

Boyd, Craig
In reply to this post by Boyd, Craig
Thanks Tony.  I have not had a chance to try a couple of your suggestions
you sent a moment ago.  But as soon as I don I will reply back.

Craig

-----Original Message-----
From: Tony Mechelynck [mailto:[hidden email]]
Sent: Tuesday, August 09, 2005 4:56 PM
To: Boyd, Craig; 'Aaron Griffin'; [hidden email]
Subject: Re: How do I execute a shell command and return the results to
VI M


----- Original Message -----
From: "Boyd, Craig" <[hidden email]>
To: "'Aaron Griffin'" <[hidden email]>; <[hidden email]>
Sent: Tuesday, August 09, 2005 11:04 PM
Subject: RE: How do I execute a shell command and return the results to VI M


>I have noticed in almost all of the solutions the DOS windows does not
>close
> and the VIM buffer/window/new instance does not update until that happens.
> Any thoughts?
[...]

That's normal. Vim can call an external program, even get output from it,
but it's not an interactive shell. Once the program finishes, the dos box
closes and Vim gets access to the program's output. Not before.

If you want to do "other Vim things" in the meantime, run the command in a
separate Dos box with redirected output:

    C:\Documents and Settings\craigboyd\>dir /S >%TEMP%\dirlist.txt

(the part up to and including the first > is a supposed "Dos prompt". You
type only the rest, of course.) When it is finished, read the output in Vim
at your leisure:

    :new $TEMP/dirlist.txt

You can of course give the temp file any name that suits you. %TEMP% is Dos
notation for the environment variable TEMP and $TEMP is Vim (and Unix)
notation for the same.

Best regards,
Tony.

Reply | Threaded
Open this post in threaded view
|

RE: How do I execute a shell command and return the results to VI M

Boyd, Craig
In reply to this post by Boyd, Craig
Hello All,

Thanks to each of you for pointing me in the right direction.  I have
accomplished what I was looking to do.

Here is the command:

:r! dir c:\temp\ /s > c:\temp\dirlist.txt | gvim c:\temp\dirlist.txt <ENTER>

This opens a new instance of VIM and does not have the DOS window hanging
around.

Thanks again!

Craig

Reply | Threaded
Open this post in threaded view
|

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

Stephen R Laniel
On Wed, Aug 10, 2005 at 08:08:10AM -0500, Boyd, Craig wrote:
> :r! dir c:\temp\ /s > c:\temp\dirlist.txt | gvim c:\temp\dirlist.txt <ENTER>

That's a few more commands than you need. For one thing,
you're outputting the directory listing to another file and
then opening that file in gvim; you could shorten it to

:r! dir c:\temp\ /s | gvim - <ENTER>

But you're also opening a new instance of gvim, which I
think is just a bad idea. It's fine if you want to do it,
but if I were in your position I'd take the advice that a
few people gave you and write a little command to

1) open a new buffer, then
2) paste the contents of the file into that buffer.

Is there any reason you need this directory listing to open
in a new instance of vim rather than withing a different
buffer?

--
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 VI M

Boyd, Craig
In reply to this post by Boyd, Craig
Thanks Stephen, the shortened command works even better!

In the wonderful world of Windows what is one more?

Thanks to Tim Chase I have a better understanding of buffers and what they
are w/n VIM.  I have no *need* to open a new instance of VIM, it just
appeared the cleanest way to me to do what I wanted to do.

I do plan to explore the buffer option as soon as a bit more time frees up.

Thanks,

Craig

-----Original Message-----
From: Stephen R Laniel [mailto:[hidden email]]
Sent: Wednesday, August 10, 2005 8:19 AM
To: Boyd, Craig
Cc: [hidden email]
Subject: Re: How do I execute a shell command and return the results to
VI M


On Wed, Aug 10, 2005 at 08:08:10AM -0500, Boyd, Craig wrote:
> :r! dir c:\temp\ /s > c:\temp\dirlist.txt | gvim c:\temp\dirlist.txt
<ENTER>

That's a few more commands than you need. For one thing,
you're outputting the directory listing to another file and
then opening that file in gvim; you could shorten it to

:r! dir c:\temp\ /s | gvim - <ENTER>

But you're also opening a new instance of gvim, which I
think is just a bad idea. It's fine if you want to do it,
but if I were in your position I'd take the advice that a
few people gave you and write a little command to

1) open a new buffer, then
2) paste the contents of the file into that buffer.

Is there any reason you need this directory listing to open
in a new instance of vim rather than withing a different
buffer?

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