Saturday, September 19, 2020

Re: How to replace string in specific paragraph only?

Hi,
thank you all for kind suggestions. I would like to use the simplest solution,
that is easily typed from the head and well understood. I specially like bellow
solution, that I have tested and it works fine.

:g/^XXX/.,/^$/s:aaa:bbb:g

Just one question,  why is there a "." character in command?
If I understand it correctly, a "." character means the line where cursor is,
and with the range used in global command, "current line" (the dot) is the
first line in range and that is the line with "XXX". If we simplify, we can
omitte the "." character and we get:

:g/^XXX/,/^$/s:aaa:bbb:g

The above command means:
- search for the line where at the beginning of the line is XXX string, and this becomes beginning of the range,
- then search empty line "^$" that is actually end of paragraph, and this becomes ending of range,
- then execute search and replace command within (and including) beginning and ending of range.

Thanks for help

--
--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/1d7d5bc1-1563-4c07-a221-ffe393c188efn%40googlegroups.com.

No comments: