0
我有一个文件:转义嵌套的替代品()的^ @字符命令导致7.2
"""I'm a multiline string.
I say
"hey, single line string",
and it says
"\they, multiline string,\nI can do multiple lines\ntoo".
and I say,
"it's cute that you think you can".
Yeah, I'm kind of a jerk."""
我可以使用嵌套substitute()
改造它:
:%s/"""\(\_.\{-}\)"""/\='"'.substitute(submatch(1),'["\\\n]','\\\0','g').'"'/g
在VIM 7.3,我得到了我想要的:
"I'm a multiline string.\
I say \
\"hey, single line string\", \
and it says \
\"\\they, multiline string,\\nI can do multiple lines\\ntoo\".\
and I say, \
\"it's cute that you think you can\".\
\
Yeah, I'm kind of a jerk."
然而,在vim 7.2,我得到了相同的输入和命令不同的结果:
"I'm a multiline string.^@I say ^@ "hey, single line string", ^@and it says ^@ "\they, multiline string,\nI can do multiple lines\ntoo".^@and I say, ^@ "it's cute that you think you can".^@^@Yeah, I'm kind of a jerk."
(其中^@
,据我所知,一个零字节)。
为什么我会得到如此不同的行为?我应该如何修改我的:%s
命令才能在7.2和7.3中获得相同的效果?
我不知道VIM可言,但它可能有一个问题与'\ 0',请尝试使用别的东西,而不是也许你。可以试试'$ 0'或$ $'' – Qtax 2013-04-06 03:44:55
我没有7.2的访问权限,只有7.3和7.0,我可以在7.0中使用以下代码:':%s /“”“\(\ _。\ { - } \)“”“/ \ = escape(substitute(submatch(1),'['\\\ n]','\\&','g'),'\')/ g'。你可以si mplify你的命令:'%s /""""\(\_.\{-}\)"""/\= escape(submatch(1),“\ n \”\\“)/ g'。 – 2013-04-06 06:00:47