Tuesday, June 30, 2020

Re: An interesting little poser [PS]

On 2020-06-30 18:33, Chris Jones wrote:
> On Mon, Jun 29, 2020 at 03:34:03PM EDT, Tim Chase wrote:
>> Try changing that line from
>>
>> $?^$?+,$g/^\[\@!.*\n\[\@!/,/\n\[\|\%$/j
>>
>> to
>>
>> $?^$?+,$g/^\[\@!.*\n\[\@!./,/\n\[\|\%$/j
>
> This indeed fixes the problem.

Great!

> Still trying to wrap my head around this bizarre
>
> :g/regex1/,/regex2/command

It helps to think of broken down. The :g command itself can take one
range:

:{range1}g/regex1/{command}

and that {command} can consist of a command *and an optional range
relative to each of those matches*. So in the above, that {command}
is

{range2}command

and that {range2} is

,/regex2/

which has the start of the range "." implied, so would be the same as

.,/regex2/

The power of this "find lines with a :g command, then operate on a
range of lines relative to each of those matches"


So it might be clearer to write that original as

$?^$?+,$ g/^\[\@!.*\n\[\@!./ .,/\n\[\|\%$/ j

11111111 2222222222222222222 3333333333333 4

where

1 = the range for the footnotes
2 = find lines where the next line is a continuation
3 = a range from this continued-line through the end of the footnote
4 = join that range of lines from #3

To learn this requires pulling together bits from several sections of
the help:

:help range
:help search-offset
:help 10.3 " particularly the ADD AND SUBTRACT section
:help 10.4

so it's certainly not a well-advertised bit of functionality.

But as you can see, it's an amazingly *powerful* bit of functionality
that I use all the time.

> Thank you very much for your help!

Thanks for the fun challenge. :-)

-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 vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20200630184130.444ac212%40bigbox.attlocal.net.

No comments:

Post a Comment