Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCode Extension Replace Entire Document's text

I know how to make a builder work with selections, but I can't work out what to put in place of my "something" comment

vscode.window.activeTextEditor.edit(builder => {
    builder.replace(/* something */, "Hello world!");
});

The desired result is that the entire active document is replaced with "Hello world!"

like image 276
Lebster Avatar asked Feb 24 '26 22:02

Lebster


1 Answers

Solved like this:

vscode.window.activeTextEditor.edit(builder => {
    const doc = vscode.window.activeTextEditor.document;
    builder.replace(new vscode.Range(doc.lineAt(0).range.start, doc.lineAt(doc.lineCount - 1).range.end), "Hello world!");
});
like image 84
Lebster Avatar answered Feb 26 '26 14:02

Lebster



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!