:sp +cmd | new buffer?

classic Classic list List threaded Threaded
20 messages Options
Reply | Threaded
Open this post in threaded view
|

:sp +cmd | new buffer?

Nicolas Bock
Hello vimlist,

I would like to :split using a command, i.e. do :sp +cmd and use the
output of that command as the input for the newly split buffer. Is
that possible? I tried several combinations with pipes and redirects
but to no avail. Any help would be greatly appreciated....


Thanks, nick
Reply | Threaded
Open this post in threaded view
|

Re: :sp +cmd | new buffer?

Bugzilla from peterp@stack.nl
Op vrijdag 8 juli 2005 17:04, schreef Nicolas Bock:
> Hello vimlist,
>
> I would like to :split using a command, i.e. do :sp +cmd and use the
> output of that command as the input for the newly split buffer. Is
> that possible?

Sure, but you probably want to use :new instead of :split (split opens a new
window using the same buffer, new opens a new buffer)

:new +r!<cmd>


Kind regards,

Peter
Reply | Threaded
Open this post in threaded view
|

Re: :sp +cmd | new buffer?

John (Eljay) Love-Jensen
Hi Peter,

I couldn't get
:new +r!sort
to work.

It just opened a new empty buffer, and did not sort the items from the prior buffer.  :-(

--Eljay

Reply | Threaded
Open this post in threaded view
|

Re: :sp +cmd | new buffer?

Antony Scriven
On Jul 08, Eljay Love-Jensen wrote:

 > I couldn't get
 > :new +r!sort
 > to work.
 >
 > It just opened a new empty buffer, and did not sort the
 > items from the prior buffer.  :-(

Hi. I don't have any of the previous mails in this thread so
I'm not sure of the context. Perhaps you are trying to do
something like this?

   :new +r#|%!sort

Antony
Reply | Threaded
Open this post in threaded view
|

Re: :sp +cmd | new buffer?

John (Eljay) Love-Jensen
Hi Antony,

>I don't have any of the previous mails in this thread so I'm not sure of the context.

The goal is:
+ split the window into a new buffer
+ run some operation (such as a shell operation: sort, grep, transmorgify, jive) on the first buffer
+ output the results of the operation into the new buffer

For example, first buffer;
one
two
three
four
five

sort all lines in first buffer into new buffer.

Usually, I do this by:
1. save buffer
2. exit vim
3. sort buffer1.txt > buffer2.txt
4. vim buffer1.txt buffer2.txt
5. rm buffer2.txt

I never thought of doing it all within vim before, until Nicolas brought it up.

--Eljay

Reply | Threaded
Open this post in threaded view
|

Re: :sp +cmd | new buffer?

A.J.Mechelynck
----- Original Message -----
From: "Eljay Love-Jensen" <[hidden email]>
To: "Antony Scriven" <[hidden email]>; <[hidden email]>
Sent: Friday, July 08, 2005 6:08 PM
Subject: Re: :sp +cmd | new buffer?


> Hi Antony,
>
>>I don't have any of the previous mails in this thread so I'm not sure of
>>the context.
>
> The goal is:
> + split the window into a new buffer
> + run some operation (such as a shell operation: sort, grep, transmorgify,
> jive) on the first buffer
> + output the results of the operation into the new buffer
[...]

You can do:

1. :split
2. :saveas newfilename
3. :1,$ !sort

This would avoid the need to quit and restart vim.

HTH,
Tony.


Reply | Threaded
Open this post in threaded view
|

Re: :sp +cmd | new buffer?

Gary Johnson
In reply to this post by John (Eljay) Love-Jensen
On 2005-07-08, Eljay Love-Jensen <[hidden email]> wrote:
> Hi Antony,
>
> >I don't have any of the previous mails in this thread so I'm not sure of the context.
>
> The goal is:
> + split the window into a new buffer
> + run some operation (such as a shell operation: sort, grep, transmorgify, jive) on the first buffer
> + output the results of the operation into the new buffer

How about this?

    :update
    :new +r\ !sort\ #

That performs the operation on the file, not the buffer.  If you
really want to perform the operation on the contents of the buffer,
then try this:

    ggyG
    :new +put\|%!sort

HTH,
Gary

--
Gary Johnson                 | Agilent Technologies
[hidden email]     | Wireless Division
                             | Spokane, Washington, USA
Reply | Threaded
Open this post in threaded view
|

Re: :sp +cmd | new buffer?

John (Eljay) Love-Jensen
Hi Gary,

ggyG
:new +put
%!sort

Thanks, that will work for me!  (Obvious, in hindsight.)

I hope that works for Nicolas too.  :-)

--Eljay

Reply | Threaded
Open this post in threaded view
|

Re: :sp +cmd | new buffer?

Nicolas Bock
In reply to this post by Gary Johnson
On 7/8/05, Gary Johnson <[hidden email]> wrote:
> That performs the operation on the file, not the buffer.  If you
> really want to perform the operation on the contents of the buffer,
> then try this:
>
>     ggyG
>     :new +put\|%!sort

Thanks Gary,

that worked for me as well. Now I am trying to understand this
command, but so far I am a little lost :) Could you explain this a
little further, please? From what I understand from the help page on
the put command, it expects a register. I couldn't find a reference to
a special register | however. And what does the % do? Could you point
me to the right help pages?

Thanks, nick
Reply | Threaded
Open this post in threaded view
|

Re: **SPAM** Re: :sp +cmd | new buffer?

A.J.Mechelynck
----- Original Message -----
From: "Nicolas Bock" <[hidden email]>
To: <[hidden email]>
Sent: Saturday, July 09, 2005 10:35 PM
Subject: **SPAM** Re: :sp +cmd | new buffer?


> On 7/8/05, Gary Johnson <[hidden email]> wrote:
>> That performs the operation on the file, not the buffer.  If you
>> really want to perform the operation on the contents of the buffer,
>> then try this:
>>
>>     ggyG
>>     :new +put\|%!sort
>
> Thanks Gary,
>
> that worked for me as well. Now I am trying to understand this
> command, but so far I am a little lost :) Could you explain this a
> little further, please? From what I understand from the help page on
> the put command, it expects a register. I couldn't find a reference to
> a special register | however. And what does the % do? Could you point
> me to the right help pages?
>
> Thanks, nick

- The register in ":put" is optional. When none is mentioned, the default
register "" is used, see ":help quotequote".
- The bar separates successive ex-commands, see ":help :bar". I don't know
why it was backslash-escaped.
- The % (when used as a range) means "the whole file", same as 1,$ (see
":help :range")


Best regards,
Tony.


Reply | Threaded
Open this post in threaded view
|

Avoid the empty line (was: :sp +cmd | new buffer?)

Bertram Scharpf
In reply to this post by Bugzilla from peterp@stack.nl
Hi,

Am Freitag, 08. Jul 2005, 17:25:23 +0200 schrieb Peter Palm:
> Op vrijdag 8 juli 2005 17:04, schreef Nicolas Bock:
>
> Sure, but you probably want to use :new instead of :split (split opens a new
> window using the same buffer, new opens a new buffer)
>
> :new +r!<cmd>

Or

  :new|r!<cmd>

By the way, how can I avoid the blank line appearing at the
top? I could say

  :new|0r!<cmd>

That moves the blank line to the bottom but doesn't avoid
it. This here seems to work:

  :new|exec "r!<cmd>"|0norm dd

Is there a smarter way?

Bertram


--
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-scharpf.de
Reply | Threaded
Open this post in threaded view
|

Re: Avoid the empty line (was: :sp +cmd | new buffer?)

Antony Scriven
On Jul 09, Bertram Scharpf wrote:

 >   :new|r!<cmd>
 >
 > By the way, how can I avoid the blank line appearing at the
 > top? I could say
 >
 >   :new|0r!<cmd>
 >
 > That moves the blank line to the bottom but doesn't avoid
 > it. This here seems to work:
 >
 >   :new|exec "r!<cmd>"|0norm dd
 >
 > Is there a smarter way?

How about :new|r#|1d

or        :new|0r!ls
          :$d

Antony
Reply | Threaded
Open this post in threaded view
|

Re: Avoid the empty line (was: :sp +cmd | new buffer?)

Bertram Scharpf
Hi Antony,

Am Montag, 11. Jul 2005, 10:14:38 +0100 schrieb Antony Scriven:

> On Jul 09, Bertram Scharpf wrote:
>
>  >   :new|r!<cmd>
>  >
>  > By the way, how can I avoid the blank line appearing at the
>  > top? I could say
>  >
>  >   :new|0r!<cmd>
>  >
>  > That moves the blank line to the bottom but doesn't avoid
>  > it. This here seems to work:
>  >
>  >   :new|exec "r!<cmd>"|0norm dd
>  >
>  > Is there a smarter way?
>
> How about :new|r#|1d
>
> or        :new|0r!ls
>           :$d

What I meant to call not smart was

  - For appending a bar (|) to a `r!' command you have to
    embedd it into an `exec'.

  - Why create a line only for deleting it immediately?

Your suggestions don't solve these. Sorry.

Bertram


--
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-scharpf.de
Reply | Threaded
Open this post in threaded view
|

Re: **SPAM** Re: :sp +cmd | new buffer?

Gary Johnson
In reply to this post by A.J.Mechelynck
On 2005-07-09, Tony Mechelynck <[hidden email]> wrote:

> > On 7/8/05, Gary Johnson <[hidden email]> wrote:

> >>     ggyG
> >>     :new +put\|%!sort

> - The bar separates successive ex-commands, see ":help :bar". I don't know
> why it was backslash-escaped.

I backslash-escaped the bar because I was trying to give both "put"
and "%!sort" as initial commands (See ":help :new" and ":help +cmd")
to the ":new" command.  In other words, the +cmd argument to ":new"
is

    put|%!sort

There was no special reason for doing that--I just got caught up in
the idea of putting all the commands following ":new" in that +cmd
argument.

Gary

--
Gary Johnson                 | Agilent Technologies
[hidden email]     | Wireless Division
                             | Spokane, Washington, USA
Reply | Threaded
Open this post in threaded view
|

Re: Avoid the empty line (was: :sp +cmd | new buffer?)

Arun Easi
In reply to this post by Bertram Scharpf
Would filtering do for you?

:new|.!<cmd>

Not all commands act as filters though!

Ignore, if this was discussed already (was not following this thread)

-Arun

On Mon, 11 Jul 2005, Bertram Scharpf wrote:

> Hi Antony,
>
> Am Montag, 11. Jul 2005, 10:14:38 +0100 schrieb Antony Scriven:
> > On Jul 09, Bertram Scharpf wrote:
> >
> >  >   :new|r!<cmd>
> >  >
> >  > By the way, how can I avoid the blank line appearing at the
> >  > top? I could say
> >  >
> >  >   :new|0r!<cmd>
> >  >
> >  > That moves the blank line to the bottom but doesn't avoid
> >  > it. This here seems to work:
> >  >
> >  >   :new|exec "r!<cmd>"|0norm dd
> >  >
> >  > Is there a smarter way?
> >
> > How about :new|r#|1d
> >
> > or        :new|0r!ls
> >           :$d
>
> What I meant to call not smart was
>
>   - For appending a bar (|) to a `r!' command you have to
>     embedd it into an `exec'.
>
>   - Why create a line only for deleting it immediately?
>
> Your suggestions don't solve these. Sorry.
>
> Bertram
>
>
> --
> Bertram Scharpf
> Stuttgart, Deutschland/Germany
> http://www.bertram-scharpf.de
>
Reply | Threaded
Open this post in threaded view
|

Re: Avoid the empty line (was: :sp +cmd | new buffer?)

Antony Scriven
In reply to this post by Bertram Scharpf
Hello

On Jul 11, Bertram Scharpf wrote:

 > Hi Antony,
 >
 > Am Montag, 11. Jul 2005, 10:14:38 +0100 schrieb Antony Scriven:
 > > On Jul 09, Bertram Scharpf wrote:
 > >
 > > > [...]
 > > >
 > > >   :new|exec "r!<cmd>"|0norm dd
 > > >
 > > > Is there a smarter way?
 > >
 > > How about :new|r#|1d
 > >
 > > or        :new|0r!ls
 > >           :$d
 >
 > What I meant to call not smart was
 >
 >   - For appending a bar (|) to a `r!' command you have to
 >     embedd it into an `exec'.
 >
 >   - Why create a line only for deleting it immediately?
 >
 > Your suggestions don't solve these. Sorry.

I solved the first problem by not using a | at all and by
using a <CR> instead :-)

As for the second, :read inserts its text below the line
that contains the cursor. I'm not sure how one might avoid a
blank line without changing the semantics of :r. I suppose
you could argue that the cursor is not really on a line. But
then you wouldn't be vi-compatible, and, to me, it would
look and feel odd because I can see a cursor there on the
screen.

Arun mentioned using a filter in another reply, e.g. :.!cat
foo but I think I'd prefer :r foo|1d anyhow: to me it's
clearer, and it is also platform independent.

Antony
Reply | Threaded
Open this post in threaded view
|

Re: Avoid the empty line (was: :sp +cmd | new buffer?)

Bertram Scharpf
Hi,

Am Dienstag, 12. Jul 2005, 09:09:59 +0100 schrieb Antony Scriven:

> On Jul 11, Bertram Scharpf wrote:
>  > Am Montag, 11. Jul 2005, 10:14:38 +0100 schrieb Antony Scriven:
>  > > On Jul 09, Bertram Scharpf wrote:
>  > >
>  > > > [...]
>  > > >
>  > > >   :new|exec "r!<cmd>"|0norm dd
>  > > >
>  > > > Is there a smarter way?
>  > >
>  > > How about :new|r#|1d
>  > >
>  > > or        :new|0r!ls
>  > >           :$d
>  >
>
> I'm not sure how one might avoid a
> blank line without changing the semantics of :r. I suppose
> you could argue that the cursor is not really on a line. But
> then you wouldn't be vi-compatible, and, to me, it would
> look and feel odd because I can see a cursor there on the
> screen.

Every programming language I ever saw can hold a string of
length 0 and an empty array or list. Only Vi/Vim seems to
know things better. Though being a convinced Vim-user, I'm
underwhelmed.

Bertram


--
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-scharpf.de
Reply | Threaded
Open this post in threaded view
|

Re: Avoid the empty line (was: :sp +cmd | new buffer?)

Charles E Campbell Jr
Quoting Bertram Scharpf <[hidden email]>:

> Every programming language I ever saw can hold a string of
> length 0 and an empty array or list. Only Vi/Vim seems to
> know things better. Though being a convinced Vim-user, I'm
> underwhelmed.

:let holdzerolengthstring=""

Works fine.
Reply | Threaded
Open this post in threaded view
|

Re: Avoid the empty line (was: :sp +cmd | new buffer?)

Bertram Scharpf
Am Mittwoch, 13. Jul 2005, 14:06:06 -0700 schrieb [hidden email]:

> Quoting Bertram Scharpf <[hidden email]>:
>
> > Every programming language I ever saw can hold a string of
> > length 0 and an empty array or list. Only Vi/Vim seems to
> > know things better. Though being a convinced Vim-user, I'm
> > underwhelmed.
>
> :let holdzerolengthstring=""
>
> Works fine.

So, I'm curious about Vim7's array feature ;-)

Bertram


--
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-scharpf.de
Reply | Threaded
Open this post in threaded view
|

Re: Avoid the empty line (was: :sp +cmd | new buffer?)

A.J.Mechelynck
In reply to this post by Bertram Scharpf
----- Original Message -----
From: "Bertram Scharpf" <[hidden email]>
To: <[hidden email]>
Sent: Wednesday, July 13, 2005 7:32 PM
Subject: Re: Avoid the empty line (was: :sp +cmd | new buffer?)
[...]

> Every programming language I ever saw can hold a string of
> length 0 and an empty array or list. Only Vi/Vim seems to
> know things better. Though being a convinced Vim-user, I'm
> underwhelmed.
>
> Bertram

Vim know about empty strings, or lists too. For instance:

    :set option=
    :let variable = ""
    " and in version 7 only
    :let listvar = []

It can even handle an empty file as long as you don't add linewise data to
it.

To avoid the empty line after

    :new
    :0r filename.txt

you can either do (as suggested)

    :new
    :r filename.txt
    :normal ggdd

or (as suggested too)

    :new filename.txt
    :saveas newfile.txt

OT: FYI, COBOL couldn't handle empty variables, strings or arrays. All its
data items had to be at least one character in length; each of its variables
was of fixed size (defined separately for each variable): numeric elementary
items had to be (IIRC) 1 to 18 characters in size, non-numeric (aka String)
elementary items, 1 to 120 characters. Group items (more or less equivalent
to C "structures") could be longer (but not shorter) than that. The number
of occurrences in an array had to be at least 1, maybe even at least 2 I'm
not sure. Rather than an empty string you used SPACES; for null numeric
data, ZERO. -- I suppose the reason for all this is that COBOL was defined
by (and for) businessmen not mathematicians.


Best regards,
Tony.