On 10/23/06, Nikolai Weibull <[EMAIL PROTECTED]> wrote:
On 10/23/06, Mikolaj Machowski <[EMAIL PROTECTED]> 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', '''')There should really be a third, optional, parameter to escape() where you can specify what character to use for escaping.
I'd suggest that 3rd arg for escape(), if it's neeed (well you always can brute-force escape things using substitute()), it would be code of the context (1-5) for which escaping is destined. Because Vim has at least 4-5 different escaping rules in different contexts: 1) escaping rules for double-quoted strings 2) escaping rules for single-quoted strings 3) escaping rules for :-command-line 4) escaping rules for regexes 5) escaping rules rules for rhs of the mapping. Escaping would be different for each of those contexts. Yakov
