Based on the wording of your question, it seems like I can assume that A
, B
, D
, and E
are not expressions that themselves contain parantheses. Based on the comments, it might not be assumed. I therefore provide two answer.
If there are not nested parantheses, then the following regular expression should work:
:%s/C(\(\_[^)]\+\))/\\SC{\1}/g
Here \_
allows the following atom to match across line boundaries, see :h \_
.
If there are nested parantheses, the substitution becomes very hard to do with a regular expression (at least in general). In this case, I would rather use a macro:
- Put the cursor on a
C
, then start recording with qa
.
- Do:
s\SC<esc>
to replace C
with \SC
.
- Do:
l%r}
to replace the last )
with }
.
- Do:
<c-o>r{
to replace the first (
with {
.
- Search for next occurance:
/C(
- Stop recording:
q
.
Now you may repeat the substitution with @a
and then @@
for the consecutive occurances.
Note: Here <esc>
is the literal escape character and <c-o>
is Ctrl+o.
C(A(f), Z())
? Is no, a simple:substitute
can do it thanks to\_.\{-}
that'll match as few things as possible on multiple lines. Otherwise, you'll need to search forC(
and apply the old trick with%
and `````