Saturday, February 11, 2017

Re: Filter-like command -- but to insert instead of replacing

On 2017-02-11 11:26, Arun wrote:
> On Sat, Feb 11, 2017 at 2:37 AM, Bram Moolenaar wrote:
>> Perhaps this will work:
>> :{range}copy {address} !cmd
>>
>
> Just wondering how this would work with :g, hope it wont be
> executing the filter against each line, rather as a whole. It would
> be useful to have a set of lines selected using :g applied against
> a filter. If the output of the filtered command be captured to a
> register (or to a destination line, like copy), that would be
> awesome. Maybe, :g, is not the right command to use, but something
> like that would be useful, IMHO.

The syntax of the :g command allows you to specify ranges for the
subsequent ex commands. So you can do things like

:g/pattern/-3,+5t$

to find all the lines matching "pattern" and copy it along with 3
lines of context before and 5 lines of context after to the bottom of
the file.

So with Bram's proposal,

:g/pattern/copy {address} !cmd

would run "cmd" for each matching line. But if each /pattern/
finds something within a block you want to process together, you
would be able to do

:g/pattern/-3,+5copy {address} !cmd

It would still run "cmd" once for every /pattern/, but it wouldn't run
it 9 times for every pattern (3 before + 1 current + 5 after) in this
example.

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