我有一个文件:
"""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 中具有相同的效果?