regex - Escaping in nested substitute() command results in ^@ characters in 7.2 -


i've got document:

"""i'm multiline string.    "hey, single line string",  , says    "\they, multiline string,\ni can multiple lines\ntoo". , say,    "it's cute think can".  yeah, i'm kind of jerk.""" 

i can use nested substitute() transform it:

:%s/"""\(\_.\{-}\)"""/\='"'.substitute(submatch(1),'["\\\n]','\\\0','g').'"'/g 

in vim 7.3, i'm trying for:

"i'm multiline string.\ \   \"hey, single line string\", \ , says \   \"\\they, multiline string,\\ni can multiple lines\\ntoo\".\ , say, \   \"it's cute think can\".\ \ yeah, i'm kind of jerk." 

however, in vim 7.2, different result same input , command:

"i'm multiline string.^@i ^@  "hey, single line string", ^@and says ^@ "\they, multiline string,\ni can multiple lines\ntoo".^@and say, ^@  "it's cute think can".^@^@yeah, i'm kind of jerk."  

(where ^@ is, far can tell, 0 byte).

why getting such vastly different behaviour? how should modify :%s command have same effect in both 7.2 , 7.3?

i think behavior you're experiencing due bug fixed patch 7.3.225:

"\n" in substitute() inside ":s" not handled correctly

vim 7.2 2008 , very outdated. should possible install latest version 7.3; if can't find proper package distribution (for windows, check binaries cream project, it's not difficult compile (e.g. mercurial sources) on linux.

if need support older vim versions , find workaround, can implement conditional:

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

Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -