On 22/04/11 08:22, Gary Johnson wrote:
On 2011-04-22, Tony Mechelynck wrote:
On 22/04/11 07:36, Adam Monsen wrote:
You've this mistake before, right?

   cat /tmp/foo.txt | vim

when you meant to do

   cat /tmp/foo.txt | vim -

Somewhere early in my Vim learning I figured out the latter, so I
usually don't repeat the mistake.

But why *is* that even a mistake? What is the purpose/origin/history
of the first example, the vim "sans-dash" behavior?

Seems like the "vim -" behavior (read text from stdin) would make
for a much more useful default.


Vim needs to read your keyboard commands from somewhere; so normally it
reads them from stdin, or if in GUI mode and there is no stdin, then
from the GUI (X11, Windows, etc.) keyboard dedvice. It's not like so
many batch command-line utilities which take no interactive input but
only command-line arguments, and thus can default to stdin if no
specific input file is given.

When Vim is not started with an editfile specified, it opens an empty
[NoName] file: it doesn't take your keyboard input as raw file data to
be edited later (maybe after you signal an end-of-file by hitting Ctrl-Z
on Windows or Ctrl-D on Unix).

In the special case when you specify stdin as input, Vim reads it all as
an input file, marks it as modified except if readonly, and then starts
reading your keypresses from somewhere, maybe stderr though it is
somewhat strange to use the "error output device" for input.

Couldn't vim just as easily use isatty(0) instead of "-" to
determine whether data is coming from stdin?  It has /dev/tty for
keyboard input.  I think that's what less does.

Regards,
Gary


On a Unix terminal it's /dev/tty which may represent /dev/tty2 on a Linux console or /dev/pty5 in konsole; on a Unix GUI I'm not sure if /dev/tty represents :0, /dev/tty7 or nothing; on Windows it's not /dev/tty but CON; on a Mac or on zOS I have no idea.

Less does not strive to be multi-platform or GUI, it is strictly a Unix curses program. IMHO it is simpler to use stdin for keyboard input whenever you don't specify explicitly that stdin has the editfile instead. For one thing there are no corner cases: either there is a lone dash on the command-line and stdin is a file to be edited, or there isn't and stdin is interactive commands.

Best regards,
Tony.
--
hundred-and-one symptoms of being an internet addict:
69. Yahoo welcoms you with your own start page

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Reply via email to