Wednesday, January 26, 2011

Re: How to replace "\" to "\\"

Hi Andy,

I can understand the pattern ifys0325 gave now (thanks ifys0325!) , but yours really scared me...  All I can know is the last one with a "\=".
The first one seems to be: find a  "\\*", without a "\" ahead, and without a "\\" followed?
And the second one: no "\" leads, but followed by a "\", and it matches "\\*" ?

I think I may wrong to parse those two, but I am not able to understand them at all... 

On Thu, Jan 27, 2011 at 5:03 AM, Andy Wokula <anwoku@yahoo.de> wrote:
Am 26.01.2011 07:34, schrieb Wayne Young:

Thanks very much. The second works!
I am still wondering how it work. It seems to replace the "
\%(\\\)\@<!\\\$(\\\)\@! " part to "\\\\". Would you help to explain the
meaning of the replaced part?

What about '\\\', the given substitute will not turn it into '\\\\'.

Better alternatives (all three supposed to do the same):
   :%s/\\\@<!\%(\\\\\)*\\\\\@!/\\&/g
   :%s/\\\@<!\%(\%(\\\\\)*\)\@>\\/\\&/g
   :%s/\\\\\=/\\\\/g

The last one is short, but will not report a useful number of changes.

--
Andy


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

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

No comments: