Re: Help sought for search & replace
am 31.01.2008 03:29:44 von muedeAnand Hariharan wrote:
> On Jan 30, 1:11 pm, James Hu
>
>>On Jan 29, 9:17 am, Anand Hariharan
>>wrote:
>>
>>
>>>I would like to replace all occurrences of '/' by '\' -- but only
>>>those instances of '/' within that portion of a line between the first
>>>and second ':'.
>>
>>>Example:
>>
>>>C:/My/Source/Tree/Code.cpp:176: x = 2/3; // Some insightful comment
>>
>>>becomes
>>
>>>C:\My\Source\Tree\Code.cpp:176: x = 2/3; // Some insightful comment
>>
>>Something along the lines of:
>>
>>:s-: -:^V^M-|-1s-/-\\-g|j
>>
>>should do the trick.
>>
>
>
> Just in case my post gave the wrong impression, I have very many such
> lines in each of a handful of files. Your solution works for *one*
> line.
>
> - Anand
:1,2s-: -:^V^M-|-1s-/-\\-g|j
Now it works for 2 lines.
More vim :
Current file :
:%s+\v(^[^:]*:[^:]*)@<=/+\\+g
All loaded files :
:bufdo %s+\v(^[^:]*:[^:]*)@<=/+\\+g
Scriptlike :
I.)
$ vim -esc ':argdo %s+\v(^[^:]*:[^:]*)@<=/+\\+g|wqa' file1 file2 ...
II.)
$ cat my_subst.vim
argdo %s+\v(^[^:]*:[^:]*)@<=/+\\+g
wqa
$ vim -esS my_subst.vim file1 file2 ...
-m