help on %s feature in gvim

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

help on %s feature in gvim

Vipin-5

In a C Source file,
there are a bunch of variables as

tv[1]
tv[2]
....
tv[234]


I want to replace them such that first '[' is replaced by '_' and
second one deleted. So file has replaced new names as

tv_1
tv_2
...
tv_234

can somebody help me with this?

%s/tv\[/tv_/g
replaces he first but how to distinguish the second from other similar
cases.

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: help on %s feature in gvim

Cyril Slobin-4

On 11/25/08, [hidden email] <[hidden email]> wrote:

>  %s/tv\[/tv_/g
>  replaces he first but how to distinguish the second from other
>  similar cases.

%s/tv\[\(\d\+\)\]/tv_\1/

--
http://slobin.pp.ru/ `When I use a word,' Humpty Dumpty said,
<[hidden email]> `it means just what I choose it to mean'

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: help on %s feature in gvim

Cyril Slobin-4

On 11/25/08, Cyril Slobin <[hidden email]> wrote:

> %s/tv\[\(\d\+\)\]/tv_\1/

Oops! /g modifier forgotten!

%s/tv\[\(\d\+\)\]/tv_\1/g

--
http://slobin.pp.ru/ `When I use a word,' Humpty Dumpty said,
<[hidden email]> `it means just what I choose it to mean'

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: help on %s feature in gvim

xulxer
In reply to this post by Vipin-5

Hi,

>In a C Source file,
>there are a bunch of variables as
>
>tv[1]
>tv[2]
>....
>tv[234]
>
>
>I want to replace them such that first '[' is replaced by '_' and
>second one deleted. So file has replaced new names as
>
>tv_1
>tv_2
>...
>tv_234
>
>can somebody help me with this?
>
>%s/tv\[/tv_/g
>replaces he first but how to distinguish the second from other similar
>cases.
>

i would use:

%s~tv\[\([^\]]*\)\]~tv_\1~g

which means replace "tv" followed by "[" followed by anything except a "]"
and save the content between "[" and "]" in \1 by tv_ and the saved
content in \1.

Kind regards

Chris


--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---