Friday, September 18, 2015

Re: Execute command on multiple ranges found by regex

Den 2015-06-03 kl. 16:06, skrev Tim Chase:
> On 2015-06-03 16:03, BPJ wrote:
>> You can define a range with regular expression(s) like:
>>
>> :/^beginfoo/+1,/^endfoo/-1!somefilter
>>
>> However if there are multiple ranges which would match only the
>> next one is filtered.
>>
>> Can you make Vim apply the command to all matching ranges
>> throughout the buffer in one go? I'm sure there is some easy
>> solution I can't find...
>
> The :g command can use a range before its command, so you could do
> something like
>
> :g/^beginfoo/+,/^endfoo/-!somefilter
>
> (I'm using the shorthand of "+" == "+1" and "-" == "-1")
>
> I love this esoteric/underused corner of Vim and it's saved me
> countless hours of work since I learned about it.

It has worked fine for me since Tim showed it to me,
but I'm afraid that I need to take it to the next level:
Is there a way to have the output of the external program be
appended below the /^endfoo/- line rather than overwriting the
input range? I realize that I could write to an external file and
then use :r! to insert it again, but I'm not keen on having the
temporary file lying around, nor on creating it in /tmp
I'm open for a solution without :g, i.e. using an ordinary range,
but even then I'd rather use marks than having to memorize line
numbers.

TIA,

/bpj

--
--
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.
For more options, visit https://groups.google.com/d/optout.

No comments: