2013-04-06 41 views
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中获得相同的效果?

+0

我不知道VIM可言,但它可能有一个问题与'\ 0',请尝试使用别的东西,而不是也许你。可以试试'$ 0'或$ $'' – Qtax 2013-04-06 03:44:55

+0

我没有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

回答

1

我想您所遇到的行为是由于补丁7.3.225固定的错误:在一个替代

“\ n”()里面“分:秒”未正确处理

Vim 7.2是从2008和非常过时。应该可以安装最新的7.3版本;如果你不能找到你的发行适当包装(适用于Windows,从Cream project检查二进制文件,它也是在Linux上compile(例如,从水银源)也不是很困难的。

如果你需要支持较老版本的Vim,你会发现一个解决方法,你可以实现一个条件:

if v:version > 703 || v:version == 703 && has('patch225') 
    " new implementation 
else 
    " workaround 
endif