sorting lines by term inside a tag

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

sorting lines by term inside a tag

Chris Lott
I need to sort lines like this:

    <li><a href="http://foo.com/">Lisa</li>
    <li><a href="http://ymmv.com/">Bart</li>
    <li><a href="http://donuts.com/">Homer</li>

by the name "inside" the a tag, thus:

    <li><a href="http://ymmv.com/">Bart</li>
    <li><a href="http://donuts.com/">Homer</li>
    <li><a href="http://foo.com/">Lisa</li>

Can I do this within Vim?

c
--
Chris Lott <[hidden email]>

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: sorting lines by term inside a tag

Eric Pruitt
On Tue, Jun 16, 2015 at 03:38:22PM -0800, Chris Lott wrote:

> I need to sort lines like this:
>
>     <li><a href="http://foo.com/">Lisa</li>
>     <li><a href="http://ymmv.com/">Bart</li>
>     <li><a href="http://donuts.com/">Homer</li>
>
> by the name "inside" the a tag, thus:
>
>     <li><a href="http://ymmv.com/">Bart</li>
>     <li><a href="http://donuts.com/">Homer</li>
>     <li><a href="http://foo.com/">Lisa</li>
>
> Can I do this within Vim?

Yes. The sort function accepts a regex as an argument that it will sort
by. Refer to :help sort. You can specify a pattern like /"[^"]\+"/ for
this instance.

Eric

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: sorting lines by term inside a tag

Gary Johnson-4
In reply to this post by Chris Lott
On 2015-06-16, Chris Lott wrote:

> I need to sort lines like this:
>
>     <li><a href="http://foo.com/">Lisa</li>
>     <li><a href="http://ymmv.com/">Bart</li>
>     <li><a href="http://donuts.com/">Homer</li>
>
> by the name "inside" the a tag, thus:
>
>     <li><a href="http://ymmv.com/">Bart</li>
>     <li><a href="http://donuts.com/">Homer</li>
>     <li><a href="http://foo.com/">Lisa</li>
>
> Can I do this within Vim?

The {pattern} argument tells the :sort command to ignore the text
matching the pattern.  See

    :help :sort

In your example, you want to skip everything through the '">', so
this would work:

    :sort /.*">/

Regards,
Gary

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: sorting lines by term inside a tag

Christian Brabandt
Hi Gary!

On Di, 16 Jun 2015, Gary Johnson wrote:

> The {pattern} argument tells the :sort command to ignore the text
> matching the pattern.  See
>
>     :help :sort

Except when you provide the 'r' flag (which I can never remember.
Anybody knows, what the r could stand for?)

Best,
Christian
--
Eine Frau mit vierzig kann heutzutage so schön sein wie mit zwanzig -
es dauert nur etwas länger.
                -- Berry Herd

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: sorting lines by term inside a tag

Tim Chase
On 2015-06-17 22:38, Christian Brabandt wrote:
> > The {pattern} argument tells the :sort command to ignore the text
> > matching the pattern.  See
> >
> >     :help :sort  
>
> Except when you provide the 'r' flag (which I can never remember.
> Anybody knows, what the r could stand for?)

I'm glad I'm not the only one thrown by this.  I remember that the
default behavior is *not* what I want/expect (I'd expect that a
search pattern would *find* the thing I want to sort on), and that
there's some flag that controls that behavior to give me what I
want.  But the same with you, I have to look it up EVERY SINGLE TIME.
As best I can tell from ex_cmds.c the "r" stands for
"r[egular e]x[pression]" search ("static int sort_rx; /* sort on
regex instead of skipping it */")

Which is indeed confusing because ":sort" can/does use a regexp even
with this flag set, just for the purposes of skipping instead of
finding the thing to sort.

-tim




--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: sorting lines by term inside a tag

Nikolay Aleksandrovich Pavlov
2015-06-18 3:04 GMT+03:00 Tim Chase <[hidden email]>:

> On 2015-06-17 22:38, Christian Brabandt wrote:
>> > The {pattern} argument tells the :sort command to ignore the text
>> > matching the pattern.  See
>> >
>> >     :help :sort
>>
>> Except when you provide the 'r' flag (which I can never remember.
>> Anybody knows, what the r could stand for?)
>
> I'm glad I'm not the only one thrown by this.  I remember that the
> default behavior is *not* what I want/expect (I'd expect that a
> search pattern would *find* the thing I want to sort on), and that
> there's some flag that controls that behavior to give me what I
> want.  But the same with you, I have to look it up EVERY SINGLE TIME.
> As best I can tell from ex_cmds.c the "r" stands for
> "r[egular e]x[pression]" search ("static int sort_rx; /* sort on
> regex instead of skipping it */")
>
> Which is indeed confusing because ":sort" can/does use a regexp even
> with this flag set, just for the purposes of skipping instead of
> finding the thing to sort.

I think mnemonic could be “Reversed regexp [meaning]”.

>
> -tim
>
>
>
>
> --
> --
> 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
>
> ---
> You received this message because you are subscribed to the Google Groups "vim_use" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
> For more options, visit https://groups.google.com/d/optout.

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.