The doc about the substitute function :h substitute() tells us:
[...] the matching with {pat} is always done like the 'magic' option is set [...]
That's cool but what if I need to use substitute() with another mode like say, verymagic or verynomagic? Is there a way to modify this behavior?
I guess a flag won't help me since the same doc topic says:
[...] When {flags} is "g", all matches of {pat} in {expr} are replaced. Otherwise {flags} should be "".
So here are my two questions:
- Is it possible to modify the magic mode used by
substitute()? - If it is not possible, what is the most elegant/efficient way to perform a substitution on a string contained in a variable with another magic mode?
{expr}part instead of the{pat}part... – statox Oct 11 '16 at 14:29:echo substitute("foo123", "\v.", "x", "g")returnsfoo123– Wolfie Oct 11 '16 at 14:45"\\v."(double quotes) or'\v'(single quotes). – xaizek Oct 11 '16 at 14:53\m,\v, or\V. There's a similar problem with case sensitivity, whereignorecaseandsmartcaseboobytrap most command / functions / whatever that use regexps, to the effect that you also need to specify either\Cor\ceverywhere where you care about case. This also makes things interesting for multibyte encodings, but that's from another story. Ah, the fractal beauty of design mistakes in Vim. :) – lcd047 Oct 11 '16 at 16:28