Improve replacing text within selection

Use case or problem

Replacing text within a selection does not work as expected. Currently, if I select a portion of a note and then use Ctrl/Cmd+h, the Find bar is filled with the entire text of the selected region. If I click in the Find bar and change the text, now the entire note will be searched and replaced.

Proposed solution

I would expect that I could select a part of a note, trigger the search & replace command, enter the text I wish to replace in the Find field, and be able to replace only matches within the selection (similar to MS Word).

As an example: say I have a whole bunch of Dataview key/value pairs that were originally in YAML, but I cut/pasted them into the actual note. I would like to select this region of the note, trigger the replace command, enter : into the Find field and :: into the Replace field, and be able to replace all instances of : within only that selection (not impacting any other part of the note).

Current workaround (optional)

Replacing multiple instances only works manually right now. So in my previous example, I would have to click Next a whole bunch of times until I got to the area where I pasted my Dataview pairs, then continue to click Replace and Next until I have fixed each instance within my desired area.

Related feature requests (optional)

I did a few cursory searches and didn’t find another request for this fix/feature. But let me know if I am just missing how to do this, or if there is already a thread that I have missed.

I wouldn’t want to lose the current behavior, but an “in selection” checkbox would be nice.

For now, another workaround is to copy the selection to a temporary note, use “replace all”, then copy the result back.

I personally don’t have a use for the current function, but maybe there’s a decent middle ground between status quo and switching entirely to my proposed behavior?

Perhaps instead this function could allow editing of the Find field without losing the selection? That way the original behavior (of placing the selection into the Find field) can be maintained while also allowing find & replace of user-entered text within only the selected region. And there would be minimal clicks between the two behaviors.

I have no background in coding at all so I have no clue how feasible this middle ground could be? The workaround is reasonable for a note or two, but I did it for like 20 notes and it got pretty clunky.

My proposed middle ground is to add to the current controls a checkbox labeled “In selection”. When the box is checked, the replacement only applies to the selected text. When the box is unchecked, the replacement applies to the whole note. That’s how I’ve seen it done elsewhere.

1 Like