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', '''')

m.




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''')


Best regards,
Tony.

Reply via email to