On 2013–01–11 Ben Fritz wrote:
> It won't be in :he :normal, because it has nothing to do with your
> normal command. :he :execute says it evaluates a string. In order
> to get a '\' character into a double-quoted string, you need to
> escape it with another '\' character, like "here is a string with
> a '\\' character". This is documented at :help expr-string as
> noted. This is consistent with most syntaxes I know of which offer
> \ as an escape character.
>
> Separately from this, '\' can have special meaning in a search, so
> to search for a literal '\' character in a search pattern, you
> also need to escape it with a backslash. You knew this already.
>
> Your task is to pass the :execute command a string containing a
> search pattern for a literal backslash. In other words, you need a
> string containing two literal backslash characters. As explained
> above, to include a *single* backslash character, you need to
> escape it with a second backslash. Since you need *two* backslash
> characters, you must escape both of them, for a total of four.
>
> > I assume the reason is that the string is parsed twice and
> > escaping needs to be done once for each step.
> >
>
> The string is parsed once, and then executed as a search pattern.
> But yes, it's because it must be parsed twice that it needs double
> backslashes.
Thanks for the detailed explanation.
> Note the other suggestion, to use a single-quoted string instead
> of a double-quoted string. In single-quoted strings, backslash has
> no special meaning and thus does not need any escaping.
Initially I thought it would be confusing, but maybe that's more
readable than four backslashes and I should settle for that one.
Marco
Friday, January 11, 2013
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment