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
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.
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
> 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
vim `find include src -name \*.[ch] -mtime -3 -print | xargs`
Regards,
Phil.
--
Philip Rhoades
GPO Box 3411
Sydney NSW 2001
Australia
E-mail: ph...@pricom.com.au
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'.
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
> 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/
These two are very nice.. thanks!
Using it with find was exactly what I wanted.
Kind regards,
Erik