On Sat, Sep 20, 2014 at 02:50:37PM -0400, Manuel Ortega wrote:
> Unsure if this is a bug or what.
> 
> Do this in a new console vim instance (console version of MacVim will
> show it too, though I am NOT reporting a MacVim problem to the wrong
> list):
> 
> :redir => foo
> :!ls -l
> :redir END
> :echo foo
> 
> What I expect is to see the usual "ls" listing of the current dir
> contents.
> 
> What I see is not that, but this:
> 
>   :!ls -l^M
> 
> In other words, the output of "ls -l" is not being redirected into the
> variable foo.

:redir only captures output that Vim itself generates.  In this case,
Vim isn't displaying the output of "ls -l".  Vim fork()/exec()s ls and
ls writes the output to the terminal.

> Instead the variable foo is getting only the !-command.
> The same goes for redirecting into files and registers.
> 
> Here's what's weird.  It works as "expected" in MacVim's GUI.

In this case, Vim isn't in a terminal, so it sets up pipes between
itself and ls, reads the output from the pipe and writes it to the gvim
window.  Since Vim is performing the output, :redir captures it.

>  (This
> might be why I came to expect it, but I could've sworn it used to work
> like this in console vim too).  Perhaps it only works in MacVim by
> fluke?

Not by fluke, but just by differences in the way that the different ways
Vim is being run cause the external command to be handled.

> Perhaps I should not have been expecting what I expected?

Correct.

> Anyway, as a point of comparison, the following works in all Vims the way
> I expect it to:
> 
> :let foo = system("ls -l")
> :echo foo

Yes, this would be the canonical way to get output from a process.

Cheers,
-- 
James
GPG Key: 4096R/331BA3DB 2011-12-05 James McCoy <[email protected]>

Attachment: signature.asc
Description: Digital signature

Raspunde prin e-mail lui