------ Original Message ------
From: "Salman Halim" <[email protected]>
To: "Vim Users" <[email protected]>
Sent: Saturday, 19 Sep, 2020 At 15:48
Subject: Re: How to replace string in specific paragraph only?
On Sat, Sep 19, 2020, 10:41 '[email protected]
<mailto:[email protected]> ' via vim_use
<[email protected] <mailto:[email protected]> > wrote:
------ Original Message ------
From: "Salman Halim" <[email protected]
<mailto:[email protected]> >
To: "vim_use" <[email protected]
<mailto:[email protected]> >
Sent: Saturday, 19 Sep, 2020 At 14:15
Subject: Re: How to replace string in specific paragraph only?
On Sat, Sep 19, 2020, 08:08 Sven Guckes <[email protected]
<mailto:[email protected]> > wrote:
* Igor <[email protected] <mailto:[email protected]> > [2020-09-19 12:55]:
> I have the following sample text file: ...
> *REPLACE RULE:*
> I need to replace string "aaa" with "bbb"
> only in paragraphs that starts with "XXX".
:g/^XXX/?^$?,/^$/s:aaa:bbb:g
i wish i could write that with less characters. ;)
Sven
I can't think of a more efficient way. The only suggestion is to perhaps
replace the last 'g' with a 'ge' on the off chance that a paragraph
doesn't contain the text so that the whole thing won't give an error
message.
Salman
--
Hi
didn't work for me - said bad range or words to that effect. This does:
:g/^XXX/.,/^$/s:aaa:bbb:g
I don't imagine aaa can occur in some other word, but in case, perhaps
\<aaa\>.
Chris W
You're going from the line that contains the text to the end of the
paragraph. Sven's solution didn't assume that the line was at the
beginning of the paragraph and started by first going back up to a blank
line, just in case.
What happened when you tried it?
I didn't type it in, because I'm using my mobile phone right now, but it
looked okay. Again, other than the addition of the e at the end.
Salman
Hi Salman
:g/^XXX/?^$?,/^$/s:aaa:bbb:g
E16: Invalid range
Press ENTER or type command to continue
It seems to me that the start line of the range we need is the current
line with the XXX.
regards - Chris
--
--
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
<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
[email protected]">[email protected]
<mailto:vim_use+<span class=> .
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_use/CANuxnEc6DBmhRa6W66pQkWP-005%2Bzwiifx6Pt-dZtTBDpez%3DTA%40mail.gmail.com
<https://groups.google.com/d/msgid/vim_use/CANuxnEc6DBmhRa6W66pQkWP-005%2Bzwiifx6Pt-dZtTBDpez%3DTA%40mail.gmail.com?utm_medium=email&utm_source=footer>
.
--
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_use/5cc29a7f.d16.174a6db3f8a.Webtop.70%40btinternet.com.