Friday, April 17, 2015

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

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

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