30

VS Code has decided to start adding ^M characters to the end of any line I edit.
They're not visible in the editor but git diff picks them up.

Weird line endings.

It wasn't doing this before, so I'm guessing I accidentally bumped some keyboard shortcut.

Does anyone know how to turn this off and have it just use regular line endings?

Henke
  • 4,445
  • 3
  • 31
  • 44
saricden
  • 2,084
  • 4
  • 29
  • 40
  • Update, it seems to only be effecting one of my repos. Still haven't figured out why. – saricden Feb 04 '21 at 02:53
  • 1
    I have the same issue that I don't remember having before but when I select lf line endings, the entire file becomes replaced as far as git diff is concerned. – RufusVS Dec 17 '21 at 20:29
  • Strange, I reverted to the repo version, did the same edits with geany, and the same issue appeared. geany says the file is crlf. time to look at the binary file.... – RufusVS Dec 17 '21 at 20:37
  • I believe this is an issue related to Git. See https://github.com/liximomo/vscode-sftp/issues/40. – Henke Oct 04 '22 at 16:35

2 Answers2

30

That's caused by the different standards used in line endings ("LineFeed" in linux and "CarriageReturn + LineFeed" in Windows).

You can set the encoding you want either by using the command palette (shift+crtl+p) and typing "end of line" (that's the mnemonic I use) until you find the command Change End of Line Sequence or by clicking the LF or CRLF button on the staus bar (near the bottom right corner).

You can then select LF or CRLF.

llema
  • 416
  • 5
  • 6
7

Go to Preferences and click on Settings. Than write LF in the search area. Next, click on "Files" under "Text Editor". You will see "Files: Eol". Eol means "End of line". In my case it was "auto", which means VSCode would use either LF or CRLF depending on the files.

The last step: change "auto" to "\n".

enter image description here

Note: this only applies to the new files.

Other solutions may be found here: How to change EOL for all files from CLRF to LF in Visual Studio Code