# 匹配分隔文本，考慮到級別

\cmd1{stuff \cmd2{other stuff}}


(stuff \cmd2{other stuff})


:%s/\\cmd1{$$.\{-}$$}/(\1)/gc


(stuff \cmd2{other stuff)}


## 正則表達式

:%s/\\cmd1{$$[^{]*{[^}]*}$$}/(\1)/gc


## 宏觀替代

1. /\\cmd1{: Find the first \cmd1
2. qq: Start recording
3. dt{: delete the \cmd1
4. %: Jump to matching }
5. r)r(: Replace curly brackets with round ones
6. n: Jump to next match
7. q: Stop recording

If you actually don't want to review the changes as you make them, you can make the macro recursive by changing the recording steps 2–7 to:

qqqqqdt{%r)r([email protected]


You can then invoke it a single time to make all the changes in one go: @q