我希望将 $ 符号之间的文本替换为放置在“\(”和“\)”之间的文本,如
replace $this text$
由
replace \(this text\)
我已经尝试过命令“%s/\$\(.*\)\$/\(\1\)/”,结果是
replace $this text$ and $this also$.
被替换为
replace \(this text$ and $this also\).
如何避免这种情况?
最佳答案
如果我理解你的问题,我想你想要:
:%s/\$\([^\$]*\)\$/\\(\1\\)/g
说明:
- 您需要转义替换字符串中的
\
- 搜索字符串中需要使用
[^\$]*
而不是.*
,即由 0 个或多个“不是美元符号”的字符组成的序列.
将替换此文本:
replace $this text$
replace $this text$ and $this also$.
使用此文本:
replace \(this text\)
replace \(this text\) and \(this also\).
关于vim - 将两个 $ 符号之间的所有内容替换为\( 和\) 之间的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55001215/