Closed farzadmf closed 4 weeks ago
Just leave the second line (the replace line) empty:
if you confirm now, it replaces everything with an empty string.
Oh cool, thank you for the quick answer @chrisgrieser !
Is there a way to also reflect it in the preview? Since it wasn't reflected in the preview, I was under the impression that it won't do anything (and clearly I was wrong)
Oh I see. Yeah, that one is a bit of a dilemma. Basically, there are two kinds of previews: a) highlight the search matches, or b) show the planned replacement.
:substitute
changes the way it does incremental previews depending on the number of slashes: % s/bla
highlights all bla
in the buffer (= a), % s/bla/
removes all bla
in the buffer, since it's assuming an empty replacement string (= b). Basically, the number of slashes determines when the preview should switch from a) to b).
However, since rip-substitute does not use any delimiters, the plugin uses the type a) preview as long as the replacement line is empty, and the type b) preview as soon as you type something into the replacement line. This works fine basically the same as with :substitute
, but it appears preview with an empty string as replacement is exactly the one edge case where it differs.
To be honest, I have no idea how to better deal with the "empty string replacement" scenario. If you got an idea, I'm all ears. Otherwise, I'm afraid, this is simply the one edge case we have to live with, basically the "price" of dropping the need for delimiters I guess. 🤔
basically the "price" of dropping the need for delimiters I guess. 🤔
Totally understandable; I guess there should be compromises, and also the fact that maybe removing things is not a very common use case.
One "hack" I can think of (really a [terrible] hack that I just thought of as I was writing this), is to maybe have a "special character" to mean "empty" and handle that separately before passing things to ripgrep
.
As I said, a super quick hack that came to my mind, so you can forget about it 😆
Checklist
Feature Requested
Hey there, I have a use case to find a pattern and delete it basically (something like
%s/blah-//
).I tried to play with the extension and researched a bit, but I'm not sure how can I specify "empty string" as the replacement.
Sorry if this is not a feature request; maybe more of a question
Relevant Screenshot
No response