why does this work?
$ find /path -name bla | vim -
But this doesn't
$ find /path -name bla | vim
Thanks Elias
Because standard input is not the same as command line arguments.
From 'man vim':
vim [options] [file ..]
and:
- The file to edit is read from stdin. Commands are read
from stderr, which should be a tty.
--
.
Yes, but what's the difference to say for example 'less'?
If I pipe the results of 'find' to 'less' I can do:
$ find /path -name bla | less
Without giving the '-' argument to 'less'. Why doesn't this work
with vim?
Thanks Elias
Elias Diem schrieb am 18.10.2011 13:50:02:
> Yes, but what's the difference to say for example 'less'?
> If I pipe the results of 'find' to 'less' I can do:
For the same reason why mplayer and wget and tar use "-":
I guess it’s intentionally coded that way…
Regards
C.M.
Because Vim can take piped commands:
[2]tim@bigbox:~/tmp$ seq 10 > test.txt
[3]tim@bigbox:~/tmp$ (echo ':5s/$/five'; echo ":wq") | vi test.txt
Vim: Warning: Input is not from a terminal
[4]tim@bigbox:~/tmp$ cat test.txt
1
2
3
4
5five
6
7
8
9
10
-tim
That's was sorta my reaction as well. I've never actually used it
for anything *practical* but it does allow you to do normal mode
commands too:
[2]tim@bigbox:~/tmp$ seq 10 > temp.txt
[3]tim@bigbox:!/tmp$ echo "3G>4jZZ" | vi temp.txt
Vim: Warning: Input is not from a terminal
[1493]tim@bigbox:~/tmp$ cat temp.txt
1
2
3
4
5
6
7
8
9
10
The only catch is that it's sometimes tricky to do things
involving control-characters or possibly where timing is of the
essence.
Notably, I also tried using
vim -w script.txt filea.txt
to record one vim session into a script, and then playing the
script back into vim on other files:
vim fileb.txt < script.txt
with a disappointing lack of success (in this test case,
filea.txt and fileb.txt were identical to begin with). Ah, well.
-tim
with a pager you'd expect its input to come from stdin, anyway.
so it was programmed differently. all a matter of history, too.
besides, the committe that came together to regulate
all this years before less and vim were created,
could not agree on a simplification or generalization..
but if you have any ideas on how to make them consistent
with the future not-yet-existent programs - let us know! ;)
Sven
--
$ export PAGER="vim -"
$ command | $PAGER
That's an answer, man. Thanks Tim.
Thank you Sven too.