How to get the screen of the previous command that was executed?

3 views
Skip to first unread message

Peng Yu

unread,
Nov 15, 2009, 10:03:25 PM11/15/09
to vim_use
Suppose I execute a shell command in ':' mode. I'm wondering how to
retrieve the output later on.

bill lam

unread,
Nov 15, 2009, 10:22:55 PM11/15/09
to vim...@googlegroups.com
On Sun, 15 Nov 2009, Peng Yu wrote:
>
> Suppose I execute a shell command in ':' mode. I'm wondering how to
> retrieve the output later on.

If you use gnu screen, may be hitting 'c-a h' to save it into a file.

--
regards,
====================================================
GPG key 1024D/4434BAB3 2008-08-24
gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3

pansz

unread,
Nov 15, 2009, 10:31:41 PM11/15/09
to vim...@googlegroups.com
bill lam 写道:

> On Sun, 15 Nov 2009, Peng Yu wrote:
>> Suppose I execute a shell command in ':' mode. I'm wondering how to
>> retrieve the output later on.
>
> If you use gnu screen, may be hitting 'c-a h' to save it into a file.
>
I think he is talking about: when the command returns and he's back in
vim, how to see the command output


bill lam

unread,
Nov 15, 2009, 10:37:47 PM11/15/09
to vim...@googlegroups.com

read the file back ':read ~/hardcopy.n' assuming that output fitted
into a screen.

Lily

unread,
Nov 15, 2009, 11:29:37 PM11/15/09
to vim_use
You can use :redir to redirect it to a file, a register, etc and then
get the output there.
Eg:
:redir @">
:!dosomething
:redir END
Now the output is in the unnamed register.

Peng Yu

unread,
Nov 15, 2009, 11:37:08 PM11/15/09
to vim_use


On Nov 15, 9:37 pm, bill lam <cbill....@gmail.com> wrote:
> On Mon, 16 Nov 2009, pansz wrote:
>
> > bill lam 写道:
> > > On Sun, 15 Nov 2009, Peng Yu wrote:
> > >> Suppose I execute a shell command in ':' mode. I'm wondering how to
> > >> retrieve the output later on.
>
> > > If you use gnu screen, may be hitting 'c-a h' to save it into a file.
>
> > I think he is talking about: when the command returns and he's back in
> > vim, how to see the command output

Yes. This is what I mean.

> read the file back ':read ~/hardcopy.n' assuming that output fitted
> into a screen.

I don't find ~/hardcopy.n.

bill lam

unread,
Nov 16, 2009, 12:00:00 AM11/16/09
to vim...@googlegroups.com

Did you use gnu screen?

Joan Miquel Torres Rigo

unread,
Nov 16, 2009, 8:19:33 AM11/16/09
to vim...@googlegroups.com

2009/11/16 Peng Yu <peng...@gmail.com>
[...]

> > I think he is talking about: when the command returns and he's back in
> > vim, how to see the command output

Yes. This is what I mean.

I have a similar problem, but I partially solve it by using command filtering.

In my case, what I want to do sometimes is to test updated fragments of bigger sql scripts and other times, like you, read or insert into buffer data from a databese (say any other command invoking bash or selecting whitespace).

The best solution which I found is to select the query which I want to test (writting it if I am retriving data instead of testing) and then normally execute ':!psql <database>'.

This replaces selected text by the result of the command but, if you want, you can restore the selection by undoing changes with 'u'. I did'nt found any way to avoid deletion of selected text yet.

Also, if you use folding (I use folding with markers), you can easily fold the query and then select like only one row.


--
Joan Miquel Torres__________________________________
Linux Registered User #164872
http://www.mallorcaweb.net/joanmiquel
BULMA: http://bulma.net http://breu.bulma.net/?l2301

Peng Yu

unread,
Nov 21, 2009, 8:25:32 PM11/21/09
to vim_use


On Nov 16, 7:19 am, Joan Miquel Torres Rigo
<joanmiq...@mallorcaweb.net> wrote:
> 2009/11/16 Peng Yu <pengyu...@gmail.com>
> [...]
>
> > > > I think he is talking about: when the command returns and he's back in
> > > > vim, how to see the command output
>
> > Yes. This is what I mean.
>
> I have a similar problem, but I partially solve it by using command
> filtering.
>
> In my case, what I want to do sometimes is to test updated fragments of
> bigger sql scripts and other times, like you, read or insert into buffer
> data from a databese (say any other command invoking bash or selecting
> whitespace).
>
> The best solution which I found is to select the query which I want to test
> (writting it if I am retriving data instead of testing) and then normally
> execute ':!psql <database>'.
>
> This replaces selected text by the result of the command but, if you want,
> you can restore the selection by undoing changes with 'u'. I did'nt found
> any way to avoid deletion of selected text yet.
>
> Also, if you use folding (I use folding with markers), you can easily fold
> the query and then select like only one row.

I still don't understand how I can retrieve previous external program
output.

In gvim, if the output of ':!some_command' is too long, I can not
scroll the bar on the right backward. Is it a bug in gvim?

sc

unread,
Nov 21, 2009, 8:59:01 PM11/21/09
to vim...@googlegroups.com
On Saturday 21 November 2009 07:25:32 pm Peng Yu wrote:

> I still don't understand how I can retrieve previous external
> program output.

let's speculate current directory for your session has lots and
lots of files on it and that your OS is some form of *nix -- you
can retrieve a full listing of the directory contents by issuing:

:r!ls -l

and the listing will be inserted into your current buffer below
current line

if all you wanted was to see the listing without adding it to
your buffer, you can undo the command with 'undo'

does this help you at all?

sc

bill lam

unread,
Nov 22, 2009, 4:11:47 AM11/22/09
to vim...@googlegroups.com
On Sat, 21 Nov 2009, Peng Yu wrote:
> In gvim, if the output of ':!some_command' is too long, I can not
> scroll the bar on the right backward. Is it a bug in gvim?

You should say inside your first message that the subject is gvim but
not vim. gvim is gui program that does not run inside a console/terminal.

see h: gui-pty

Gary Johnson

unread,
Nov 22, 2009, 2:33:22 PM11/22/09
to vim_use
On 2009-11-21, Peng Yu wrote:
> On Nov 16, 7:19 am, Joan Miquel Torres Rigo
> <joanmiq...@mallorcaweb.net> wrote:
> > 2009/11/16 Peng Yu <pengyu...@gmail.com>
> > [...]
> >
> > > > > I think he is talking about: when the command returns and he's back in
> > > > > vim, how to see the command output
> >
> > > Yes. This is what I mean.

> I still don't understand how I can retrieve previous external program


> output.
>
> In gvim, if the output of ':!some_command' is too long, I can not
> scroll the bar on the right backward. Is it a bug in gvim?

This is not a bug, but it is a limitation of the terminal emulation
features of gvim. I can't find this in the help files, but I seem
to recall from earlier discussions of this that Bram does not want
vim to become a terminal emulator. If you need the features of a
terminal, run vim (not gvim) in a terminal window. If you execute
":!" commands from within gvim, you will be limited in what you can
do with the output. Various solution have already been
presented in this thread, but they all require planning ahead to
capture the output of a ":!" command.

Regards,
Gary


pansz

unread,
Nov 23, 2009, 7:59:03 PM11/23/09
to vim...@googlegroups.com
Peng Yu 写道:

>
> In gvim, if the output of ':!some_command' is too long, I can not
> scroll the bar on the right backward. Is it a bug in gvim?

It is the designed way, in gvim it is impossible to see them. The
official document had described this:


Typeahead while the external command is running is often lost. This happens
both with a pipe and a pseudo-tty. This is a known problem, but it seems it
can't be fixed (or at least, it's very difficult).

If you want terminal features you must use console vim.

Peng Yu

unread,
Nov 24, 2009, 10:31:31 AM11/24/09
to vim_use


On Nov 15, 11:00 pm, bill lam <cbill....@gmail.com> wrote:
> On Sun, 15 Nov 2009, Peng Yu wrote:
>
> > On Nov 15, 9:37 pm, bill lam <cbill...@gmail.com> wrote:
> > > On Mon, 16 Nov 2009, pansz wrote:
>
> > > > bill lam 写道:
> > > > > On Sun, 15 Nov 2009, Peng Yu wrote:
> > > > >> Suppose I execute a shell command in ':' mode. I'm wondering how to
> > > > >> retrieve the output later on.
>
> > > > > If you use gnu screen, may be hitting 'c-a h' to save it into a file.
>
> > > > I think he is talking about: when the command returns and he's back in
> > > > vim, how to see the command output
>
> > Yes. This is what I mean.
>
> > > read the file back ':read ~/hardcopy.n' assuming that output fitted
> > > into a screen.
>
> > I don't find ~/hardcopy.n.
>
> Did you use gnu screen?

I have never used gnu screen. In what case, I'd better use it?

Peng Yu

unread,
Nov 24, 2009, 10:32:47 AM11/24/09
to vim_use
This is helpful.

bill lam

unread,
Nov 24, 2009, 10:48:24 AM11/24/09
to vim...@googlegroups.com
On Tue, 24 Nov 2009, Peng Yu wrote:

screen is used with terminal/console mode programs. You don't need it
for gui programs like gvim.

Christian Brabandt

unread,
Nov 30, 2009, 1:29:21 AM11/30/09
to vim...@googlegroups.com
Hi Joan!

On Mo, 16 Nov 2009, Joan Miquel Torres Rigo wrote:

> The best solution which I found is to select the query which I want to test
> (writting it if I am retriving data instead of testing) and then normally
> execute ':!psql <database>'.
>
> This replaces selected text by the result of the command but, if you want,
> you can restore the selection by undoing changes with 'u'. I did'nt found
> any way to avoid deletion of selected text yet.

Well you could write a wrapper (e.g. a shell script), that first outputs
the input, and afterwards processes the input with sql. That's no
generic solution and a little bit awkward.

regards,
Christian
--
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x].

Tony Mechelynck

unread,
Dec 5, 2009, 5:32:35 AM12/5/09
to vim_use
On 22/11/09 20:33, Gary Johnson wrote:
> On 2009-11-21, Peng Yu wrote:
[...]
>> In gvim, if the output of ':!some_command' is too long, I can not
>> scroll the bar on the right backward. Is it a bug in gvim?
>
> This is not a bug, but it is a limitation of the terminal emulation
> features of gvim. I can't find this in the help files, but I seem
> to recall from earlier discussions of this that Bram does not want
> vim to become a terminal emulator. If you need the features of a
> terminal, run vim (not gvim) in a terminal window. If you execute
> ":!" commands from within gvim, you will be limited in what you can
> do with the output. Various solution have already been
> presented in this thread, but they all require planning ahead to
> capture the output of a ":!" command.
>
> Regards,
> Gary

:help design-not


Best regards,
Tony.
--
hundred-and-one symptoms of being an internet addict:
219. Your spouse has his or her lawyer deliver the divorce papers...
via e-mail.
Reply all
Reply to author
Forward
0 new messages