ls |vim -c "..." freezes Windows Command Prompt

4 views
Skip to first unread message

bgold12

unread,
Dec 14, 2008, 2:49:23 AM12/14/08
to vim_use
Hey,

I've just discovered this amazing thing where I can call vim from the
Windows Command Prompt and execute a command directly with the -c
flag, which makes a certain C program I'm trying to write easier. But
I've also discovered that when I do this from the command prompt
myself (i.e. not from a program), and when I pipe input from the
cygwin ls command to vim, I get a strange error message, and then vim
freezes. For example, I'll type the following in Command Prompt and
press enter:

ls |vim -c "normal ia"

Then I get this error message that says "Vim: Warning: Input is not
from a terminal", and then vim seems to start up successfully with a
new (empty) file that has the "a" as the only contents. Then vim runs
full-out, hogging all my CPU, and I can't do anything, so I have to
close the shell completely.

I actually don't really need to do this (pipe ls to vim); I was just
experimenting, but I would like to know what's going on here. Seems
like an error of some kind.

Thanks.

Matt Wozniski

unread,
Dec 14, 2008, 2:59:36 AM12/14/08
to vim...@googlegroups.com
On Sun, Dec 14, 2008 at 2:49 AM, bgold12 wrote:
>
> Hey,
>
> I've just discovered this amazing thing where I can call vim from the
> Windows Command Prompt and execute a command directly with the -c
> flag, which makes a certain C program I'm trying to write easier. But
> I've also discovered that when I do this from the command prompt
> myself (i.e. not from a program), and when I pipe input from the
> cygwin ls command to vim, I get a strange error message, and then vim
> freezes. For example, I'll type the following in Command Prompt and
> press enter:
>
> ls |vim -c "normal ia"

Running vim that way uses the output of 'ls' as commands to execute.
For example:

echo -e "ihello\e:w! /tmp/vimout.txt\n:q\n" | vim

would use vim to do about the same thing as

echo "hello" >/tmp/vimout.txt

What you were looking for is something like

ls | vim -

where the dash at the end tells vim to treat the text on its standard
input as a buffer to be edited, rather than commands to be run.

~Matt

Tony Mechelynck

unread,
Dec 14, 2008, 3:00:41 AM12/14/08
to vim...@googlegroups.com

To edit the file on stdin (the output of ls) add a dash at the end of
the Vim command-line.

See :help --


Normally, Console Vim expects stdin to be the keyboard and stdout to be
the display. Here, you are reassigning stdin to something other than
keyboard commands to Vim, so you need to tell it about the change.


Best regards,
Tony.
--
Please take note:

Reply all
Reply to author
Forward
0 new messages