visual-studio-codevscode-extensionseol

Changing file EOL with vscode extension API


Can I silently change end of line sequence in VSCode?
Something like this:

vscode.commands.executeCommand("workbench.action.editor.changeEOL", "LF");

Solution

  • The solution is to call edit method of active TextEditor. For example:

    vscode.window.activeTextEditor.edit(builder => { 
        builder.setEndOfLine(vscode.EndOfLine.LF);
    })
    

    UPD
    Or if you want TexEdit result you can use this one:

    vscode.TextEdit.setEndOfLine(vscode.EndOfLine.LF)
    

    "vscode" here is vscode module: require('vscode')