Saturday, April 18, 2015

Re: How to add new line after comma character if command is not part of a function?

On Saturday, April 18, 2015 at 12:57:55 AM UTC+8, Igor Forca wrote:
> Hi,
>
> *** Sample data ***
> sub(abc,xxx)
> sub(abc),abs(aaaa,bbb)
> avg(sub(abc),abs(aaaa,bbb)),del(xxx,yy)
> avg(sub(abc),abs(aaaa,bbb))
> trig(abc,bbb,ccc,sum(abc))
> *******************
>
> In above text I would like to add a new line character after comma in comma is not part of the function parameter. OK, I can explain this by rules.
>
> Rule 1:
> Type in command /( and press enter the ( is searched for.
> Press % to jump to the closing ).
> If comma character , is between above opening ( and closing ) character then there should be NO new line after comma character, simply because comma
> is delimiter between parameters inside function. This rule applies for instance for line 1.
>
> Rule 2:
> Now pressing n character to jump to next opening ( character.
> If n jumps over comma character then new line character should be added after comma, because comma in this case is not a function parameter delimiter.
> This rule applies to line two. Why? Cursor at first ( character [position 4] pressing % jumps on position [8]. Now pressing n jumps over comma character [position 9] to ( character in position [13]. So after comma [position 9] should be a new line.
>
> So final result should be:
> *******************
> sub(abc,xxx)
> sub(abc), <--- new line added
> abs(aaaa,bbb)
> avg(sub(abc),abs(aaaa,bbb)), <--- new line added
> del(xxx,yy)
> avg(sub(abc),abs(aaaa,bbb))
> trig(abc,bbb,ccc,sum(abc))
> *******************
>
> Any idea how to write search and replace?
> Thanks


Probably this can be done with searching&replacing, if Vim allow recursive RE pattern. first search for the outermost matching braces:

/\((\([^()]\{-}\1\)*[^()]\{-})\)

and after the text fields was highlighted do substitution where there's no highlighting, using the :h sub-replace-special feature.

But currently Vim doesn't permit recursive regular expression, so the above pattern would be considered illegal

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