Re: Help sought for search & replace

Re: Help sought for search & replace

am 31.01.2008 03:29:44 von muede

Anand Hariharan wrote:
> On Jan 30, 1:11 pm, James Hu wrote:
>
>>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

Re: Help sought for search & replace

am 31.01.2008 11:52:04 von muede

muede73 wrote:
> Anand Hariharan wrote:
>
>> On Jan 30, 1:11 pm, James Hu wrote:
>>
>>> 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 ':'.


Current file :
:%s+\v(^[^:]*:[^:]*)@<=/+\\+g

All loaded files :
:bufdo %s+\v(^[^:]*:[^:]*)@<=/+\\+ge

Scriptlike :
I.)
$ vim -esc ':argdo %s+\v(^[^:]*:[^:]*)@<=/+\\+ge|wqa' file1 file2 ...

II.)
$ cat my_subst.vim
argdo %s+\v(^[^:]*:[^:]*)@<=/+\\+ge
wqa
$ vim -esS my_subst.vim file1 file2 ...

Better add the 'e' flag.

-m