On 10/23/06, A.J.Mechelynck <[EMAIL PROTECTED]> wrote:
Mikolaj Machowski wrote: > Hello, > > I understand that escape() was primarily designed to escape strings when > passing to system functions, but personally I never used that and in > didn't noticed such use in various scripts but very often it is used to > escape various charaters in Vim's own regexp matching or passing one > string to some other Vim command. > > Hence is the problem: when escaping ' with escape(), character is > prepended with \ which doesn't make sense when passing it to other Vim > command because proper way to escape it in Vim is doubling it with > another '. Example:: > > :echo escape('as''df', '''')
escape() is for a double-quoted string, or for the unquoted strings accepted by some commands. For a single-quoted string you need something else, such as substitute(substitute(string,"'","''","g"),'^.*$','''\0''')
I realize that you want to provide a solution to a problem and that's fine, but you don't seem to have understood Mikolaj's statement/question. He begins with "I understand that escape() was primarily designed to escape strings when passing to system functions", so I think he can figure out the solution well enough, and he's instead asking why escape() hasn't been adopted to other areas of use, such as escaping for regexes, which is a very common operation, or passing a string to another Vim command. Also, why would you ever write substitute(x, '^.*$', '''\0''') instead of "'" . x . "'"? nikolai