query about vim replacement

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

query about vim replacement

Kumar Vaddi
Hi,
    I want to replace syntax in files like below in gvim. The file has 90000 lines. manually replacing is very tough.

1) -from {  replaced with  -from {abc.abc_core.
2) -from [a-z]+ replaced with -from abc.abc_core.[a-z]+
3) -from [A-Z]+ replaced with -from abc.abc_core.[A-Z}+
4) -from * replaced with -from abc.abc_core.*

can you please help me in this regard.
Thanks,
Kumar

--
--
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 because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: query about vim replacement

Tony Mechelynck
On Thu, Dec 13, 2018 at 4:14 PM Kumar Vaddi <[hidden email]> wrote:

>
> Hi,
>     I want to replace syntax in files like below in gvim. The file has 90000 lines. manually replacing is very tough.
>
> 1) -from {  replaced with  -from {abc.abc_core.
> 2) -from [a-z]+ replaced with -from abc.abc_core.[a-z]+
> 3) -from [A-Z]+ replaced with -from abc.abc_core.[A-Z}+
> 4) -from * replaced with -from abc.abc_core.*
>
> can you please help me in this regard.
> Thanks,
> Kumar

This looks like a job for the :s[ubstitute] command (see ":help :s"
and ":help pattern-overview"). Note that Vim patterns are similar to,
but subtly different from, those used by Perl, grep, less, etc. For
option 4, just replace "-from " by "-from abc.abc_core." by means of
        :%s/-from /\0abc\.abc_core\./g
The ending /g is only necessary if there can be more than one
replacement per line. In addition, insert ^ before -from if it must be
at the start of a line.
For the others, the same with /gc at the end instead of /g (or /c
instead of nothing) will let you answer y or n for each replacement.
Or slightly more complex patterns will let you specify more in detail
what to replace by what.

After studying the two help topics mentioned above, and what comes
around them, you should be able to (a) understand what my example
above is doing and how, and (b) how to make it more selective.

Best regards,
Tony.

--
--
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 because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Kit
Reply | Threaded
Open this post in threaded view
|

Re: query about vim replacement

Kit
In reply to this post by Kumar Vaddi
2018-12-13 16:08 GMT+01:00, Kumar Vaddi <[hidden email]>:

> Hi,
>     I want to replace syntax in files like below in gvim. The file has 90000
> lines. manually replacing is very tough.
>
> 1) -from {  replaced with  -from {abc.abc_core.
> 2) -from [a-z]+ replaced with -from abc.abc_core.[a-z]+
> 3) -from [A-Z]+ replaced with -from abc.abc_core.[A-Z}+
> 4) -from * replaced with -from abc.abc_core.*
>
> can you please help me in this regard.
> Thanks,
> Kumar

:%s/-from {/-from {abc.abc_core./g
:%s/-from \([A-Za-z*]\+\)/-from abc.abc_core.\1/g
--
Kit

--
--
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 because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.