8

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

vscode.commands.executeCommand("workbench.action.editor.changeEOL", "LF");
Gama11
  • 31,714
  • 9
  • 78
  • 100
Rus
  • 718
  • 2
  • 6
  • 19

3 Answers3

13

You can add this line to your user preferences settings (CTRL + ,):

"files.eol": "\n"
Ali Radmanesh
  • 2,248
  • 22
  • 26
5

On the bottom right of vs code it will say lf or crlf. Click there and it will give an option to change.

pic of vs code

KyleMit
  • 30,350
  • 66
  • 462
  • 664
  • 5
    That only applies it to the current file. Is there a way to change it for every file in the project? Just changing it in the Settings does not do this unfortunately. – Micros May 09 '19 at 08:14
1

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')

Rus
  • 718
  • 2
  • 6
  • 19
  • Is this a script snippet ? How to execute it ? – Alan Feb 26 '19 at 06:59
  • 1
    @Alan, you need to call `edit` method of `TextEditor` object. For example: `require('vscode').window.activeTextEditor.edit(builder => { builder.setEndOfLine(vscode.EndOfLine.LF); })` – Rus Feb 27 '19 at 07:17
  • 1
    Although this is the accepted answer, it would be improved with simpler instructions within the body and not a comment. Specifically how would one "call the edit method" for example. – Dylan Kinnett May 11 '21 at 14:16
  • It might be the solution but it should contain the instructions as to where and how a person should execute the code. Poorly answered. – Mehmet Eyüpoğlu Jun 10 '22 at 13:54
  • This question is about VSCode extension development. I produced a code, that solves the problem. Where and how execute the code (of extension you're working at) is not the instruction for this question i hope) – Rus Jun 11 '22 at 16:23