Find and replace function

Trying to create a find and replace all function

IDK if there's a better, easier, more direct way of doing this.

Tried using KM, it works well and it's fast, it just doesn't process selected text, I need to copy it..