Snippet: find all X and replace them for Y in selected text

How to make this snippet?

I want to find all X and replace them for Y in a selected text only.

Thank you in advance :smiley:

You can’t do this with a snippet, however it’s totally doable with a userscript:

var editor = require("ko/editor");
var selection = editor.getSelection();
replacement = selection.replace(/foo/g, "bar");
editor.replaceSelection(replacement);
1 Like