On Friday, January 11, 2013 2:08:25 AM UTC-6, Marco wrote:
> 
> This only explains the need to escape a backslash with a backslash,
> 
> not the need for double-escaping. And I didn't find the information
> 
> either in :h normal or :h execute.

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.

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.

-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Reply via email to