Skip to main content
added headings to make reading easier
Source Link

What I want

Is there aA 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 getsee the replacement candidates, BUT in ivy-occur buffer file names + line numbers interfere heavily withbut 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 thisread-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.

Is there a convenient way (with preview, interactivity) to replace regex multi-line matches across many files?

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 get the replacement candidates, BUT in ivy-occur buffer file names + line numbers interfere heavily with replacement.

The crux of the problem is that file-names and line numbers are read-only, and regex-replace fails if any part of this 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.

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.

explained why replacement fails in ivy-occur buffer
Source Link

Is there a convenient way (with preview, interactivity) to replace regex multi-line matches across many files?

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.

But if I try the same with multiMulti-line matchessearch works, and I can get the replacement candidates, BUT in ivy-occur buffer file names + line numbers interfere heavily with regex matchingreplacement.

The crux of the problem is that file-names and line numbers are read-only, and regex-replace fails if any part of this 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.

Is there a convenient way (with preview, interactivity) to replace regex multi-line matches across many files?

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.

But if I try the same with multi-line matches, file names + line numbers interfere heavily with regex matching. Here's an example 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.

Is there a convenient way (with preview, interactivity) to replace regex multi-line matches across many files?

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 get the replacement candidates, BUT in ivy-occur buffer file names + line numbers interfere heavily with replacement.

The crux of the problem is that file-names and line numbers are read-only, and regex-replace fails if any part of this 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.

Source Link

How to do multi-line regex replace across multiple files?

Is there a convenient way (with preview, interactivity) to replace regex multi-line matches across many files?

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.

But if I try the same with multi-line matches, file names + line numbers interfere heavily with regex matching. Here's an example 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.