2

What I want

A convenient way (with preview, interactivity) to replace regex multi-line matches across many files


What I already have

I know how to do this for single-line matches. I use counsel-rg, open ivy-occur buffer with C-c o, and can make my edits there.

Multi-line search works, and I can see the replacement candidates, but replacement is painful.


Why what I have is not enough

The crux of the problem is that file-names and line numbers in ivy-occur buffer are read-only, and regex-replace fails if any part of read-only text is matched.

Here's an example of search results ivy-occur for regex :PROPERTIES:\n.*?\n:END::

60 candidates:
./README.org:1::PROPERTIES:
./README.org:2::header-args: :comments link :noweb yes
./README.org:3::END:
./README.org:6::PROPERTIES:
./README.org:7::ID:       41e08286-2ccc-4c5b-b1ed-10d7dde499d3
./README.org:8::END:
...

I can get creative, and use something like negative look-behind (?<=org:\d*?:) from pcre2el package, to make edits line-by-line and not touching read-only text in the buffer. But this seems like a lot of hoops to jump through for a simple operation.

4
  • Doesn't :PROPERTIES:\n.*\n.*:END: match? Commented Mar 12 at 13:28
  • And if you want to match multiple lines between :PROPERTIES: and :END: you need a bit more in the middle: you need to group the .*\n that matches a single line and apply *? or +? on the group. Commented Mar 12 at 14:12
  • 1
    @NickD The problem that I have is not matching per se, the problem is occur buffer. It's created with file names + line numbers, which makes replacement painful. Commented Mar 12 at 14:28
  • Right - I see what you mean but I don't know of a way to do what you want. I hope somebody comes up with a good answer. Commented Mar 14 at 5:17

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.