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