Wednesday, June 3, 2015

Re: Execute command on multiple ranges found by regex

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.

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

No comments:

Post a Comment