-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Description
Currently rg --json provides full text of every match in submatch array item's match.text field. This ticket is to request addition of replace.text field in submatch array items. The replace.text fields will only get added if user passed the replace flag -r and the replace string. For usual searches without replace (-r), replace.text will not get added & the json output will be same as it is today.
Motivation: This will allow using rg --json to become a real alternative to Vim's internal search-and-replace functionality :%s/<match_pattern>/<replace_pattern>/g that is based on legacy vim regex format. Given the start-end position of submatches are known, developers would just need replacement text information to delete match.text from text files, and replace it with replace.text. Given its in a clean json format, it would be easier to allow batch processing, replace an occurrence of interest, and even selectively rollback* easily. The same information can be used in other tools/scripts as well to do search-and-replace. Moreover, currently there is no way of doing this using rg with Vim & just having it integrated as a search tool makes it less preferred over vim's built in regex engine because: users will have to learn new regex syntax that they cannot use for capture group based complex text replace. This will force a user to either learn both syntaxes (vim regex, and rust regex), or just stick with vim regex (thus limiting adoption of rg). Having this feature will also bring the power of pcre2 search and replace to Vim.
* Selective rollback is different from undo. Undo by its very nature is LIFO, whereas selective rollback can be in any order the user wishes (without having to undo all steps after it). It's easy to build something like that in Vim with information asked in this ticket.
NOTE: If you decide to add this, then please cover those corners where entire line is a match, and no submatches are printed.