xargs vim

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

xargs vim

enk

Hi..

Why can't i pipe to xargs vim? I mean.. I can, but something is not right.

After doing,

$ ls somefile | xargs vim

and exiting, the terminal is fubar and has to be reset.

And this does the same:
$ ls somefile | sed 's/^/vim /' | bash

What's the problem?

Regards,
Erik Wognsen

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

RE: xargs vim

Gene Kwiecinski

>Why can't i pipe to xargs vim? I mean.. I can, but something is not
right.
>After doing,
>$ ls somefile | xargs vim
>and exiting, the terminal is fubar and has to be reset.

Only to hazard a guess, but 'vim' assumes an interactive tty input (eg,
'sh -i'), ie, tied to a screen, but streaming a command might assume
batch-mode.  It *might* be divorcing the process associated with 'vim'
from the tty, and leaving it zombied somehow after it's finished.

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: xargs vim

Gary Johnson-4
In reply to this post by enk

On 2009-05-28, Erik Wognsen wrote:

> Hi..
>
> Why can't i pipe to xargs vim? I mean.. I can, but something is not right.
>
> After doing,
>
> $ ls somefile | xargs vim
>
> and exiting, the terminal is fubar and has to be reset.
>
> And this does the same:
> $ ls somefile | sed 's/^/vim /' | bash
>
> What's the problem?

When I do that, I see this message briefly at the top of the screen:

    Vim: Warning: Input is not from a terminal

The problem is that xargs runs its argument commands in an
environment in which standard input is not the user's terminal.
Here's one way around that:

    ls somefile | xargs sh -c '</dev/tty vim $*'

What I usually do, though, in situations like that is to run vim
like this:

    vim $(ls somefile)

That assumes, of course, that the number of files doesn't exceed
MAX_ARGS or whatever that limit is called.

Regards,
Gary



--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: xargs vim

Gary Johnson-4
In reply to this post by Gene Kwiecinski

On 2009-05-28, Gene Kwiecinski wrote:

> Sorry, deleted the original email, gotta reply to something else...

You couldn't just create a new thread?

> What about just plain 'vim *' on the command line?  Some reason that
> doesn't work?

That works fine for simple cases where the file names match some
pattern, but it doesn't work for cases where you want to edit the
files that result from some complicated search pipeline such as this
one:

    find include src -name \*.[ch] -mtime -3 -print

Regards,
Gary



--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: xargs vim

philip_rhoades

Gary,


On 2009-05-29 02:50, Gary Johnson wrote:

> On 2009-05-28, Gene Kwiecinski wrote:
>
>> Sorry, deleted the original email, gotta reply to something else...
>
> You couldn't just create a new thread?
>
>> What about just plain 'vim *' on the command line?  Some reason that
>> doesn't work?
>
> That works fine for simple cases where the file names match some
> pattern, but it doesn't work for cases where you want to edit the
> files that result from some complicated search pipeline such as this
> one:
>
 >      find include src -name \*.[ch] -mtime -3 -print


vim `find include src -name \*.[ch] -mtime -3 -print | xargs`

Regards,

Phil.
--
Philip Rhoades

GPO Box 3411
Sydney NSW 2001
Australia
E-mail:  [hidden email]

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

RE: xargs vim

Gene Kwiecinski
In reply to this post by Gary Johnson-4

>>Sorry, deleted the original email, gotta reply to something else...
>You couldn't just create a new thread?

Mmmmmmm, no.


>>What about just plain 'vim *' on the command line?  Some reason that
>>doesn't work?

>That works fine for simple cases where the file names match some
>pattern, but it doesn't work for cases where you want to edit the
>files that result from some complicated search pipeline such as this
>one:
>    find include src -name \*.[ch] -mtime -3 -print

Unno, he specified 'ls somefile |...', which to me would simply return
"somefile" on its own line, to be passed along to 'xargs'.  So either
just use the given filename, or something like '*' for everything in the
directory, if "somefile" [sic] would actually be a directory-name.

'foo' == file:

        > ls foo
        foo
        > _

'foo' == directory:

        > ls foo
        file1
        file2
        file3
        ...
        fileN
        > _

I just suggested a wildcard would be easier than going the roundabout
way through 'ls' and 'xargs'.

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: xargs vim

Anton-3
In reply to this post by Gary Johnson-4

2009/5/28 Gary Johnson <[hidden email]>:

>
> On 2009-05-28, Gene Kwiecinski wrote:
>
>> Sorry, deleted the original email, gotta reply to something else...
>
> You couldn't just create a new thread?
>
>> What about just plain 'vim *' on the command line?  Some reason that
>> doesn't work?
>
> That works fine for simple cases where the file names match some
> pattern, but it doesn't work for cases where you want to edit the
> files that result from some complicated search pipeline such as this
> one:
>
>    find include src -name \*.[ch] -mtime -3 -print
>

Another way of doing this:

find include src -name \*.[ch] -mtime -3 -print | vim -

, and then with series of CTRL-W_f CTRL-W_q to examine files from
the resulting list. (I use this technique pretty much to visit
files, which are changed in my subversion working copy - "svn
status | vim -")

--
Anton

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: xargs vim

Ken Bloom-2
In reply to this post by philip_rhoades

On Fri, 29 May 2009 02:55:28 +1000, Philip Rhoades wrote:

> Gary,
>
>
> On 2009-05-29 02:50, Gary Johnson wrote:
>> On 2009-05-28, Gene Kwiecinski wrote:
>>
>>> Sorry, deleted the original email, gotta reply to something else...
>>
>> You couldn't just create a new thread?
>>
>>> What about just plain 'vim *' on the command line?  Some reason that
>>> doesn't work?
>>
>> That works fine for simple cases where the file names match some
>> pattern, but it doesn't work for cases where you want to edit the files
>> that result from some complicated search pipeline such as this one:
>>
>  >      find include src -name \*.[ch] -mtime -3 -print
>
>
> vim `find include src -name \*.[ch] -mtime -3 -print | xargs`
>
> Regards,
>
> Phil.

Piping through xargs is a no-op in this case.

vim `find include src -name \*.[ch] -mtime 3 -print`

is what you want



--
Chanoch (Ken) Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology.
http://www.iit.edu/~kbloom1/


--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

enk
Reply | Threaded
Open this post in threaded view
|

Re: xargs vim

enk
In reply to this post by Gary Johnson-4

>    ls somefile | xargs sh -c '</dev/tty vim $*'
>
>    vim $(ls somefile)

These two are very nice.. thanks!

Using it with find was exactly what I wanted.

Kind regards,
Erik

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---