regex - VIM: Replace function call without the arguments -
How do I search for a function call, but how can I do without the arguments of the function?
to
foobar: arg1, arg2;
My goal is to search and replace the
foobar (arg1, arg2) to keep
I> Arg1, arg2 .
How do I solve it? Is there any best practice?
Try it out:
Insert a row at the top of the file - We will write a macro here (this letter is not O, zero).
ggO followed by an open bracket for a string of word-letters Instructions to do, and
/ \ w * (/ e> & lt; Ctrl-M & gt; < P> Then we leave the cursor at the end of the match, go to the mailing bracket and replace it with a semicolon Other Back to the Front (ctrl-letter o then, :
This field will be from Change:
P> s: gt; & lt; Ctrl-V & gt; & lt; Esc & gt; < / Code> then perform this macro again (it is assumed that it is q register
@q Our macro is done, exhaust insert mode (should read your line: / \ w * (/ a ^ m% r; ^ OS: ^ [[[@ q] now)
& lt; Esc & gt; Drag the line q register (which also removes it from the current file, sends back its file. Finally, Big moment: Created by us Execute recursive macro @
/ Code> register, which will replace the entire file.
@q BENEFITS : This handles nested functions properly, because it is not relying on those regular expressions, who have brackets Instead, we rely on % to match the parentheses. Demo:
foo (Bar, baz) foo (foo (bar), foo (foo, foo, foo)) foo (bar (baz ())) < P> Edit : Typo ( \ w , not in search \ e ).
Comments
Post a Comment