Thursday, December 13, 2018

Re: query about vim replacement

On Thu, Dec 13, 2018 at 4:14 PM Kumar Vaddi <kumar.vsrp@gmail.com> 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 vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment