356

How can I display lineendings (CR,LF) in Visual Studio Code (not in Visual Studio)?

At the moment there is only the little statusbar menu which display/change the line ending if the actual file. But sometimes it would be great to see the line endings directly in every line especially when there are mixed line endings (not good, but this happens from time to time).

I use the following settings, but none of them show the line endings.

"editor.renderWhitespace": true,
"editor.renderControlCharacters": true,
"editor.renderIndentGuides": true

Is there a setting for lineendings?


I've opened a issue on GitHub: Possibility to display line endings in text area #12223

Soham Kamani made an extensions for this: code-eol

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
Michael Aigner
  • 4,820
  • 4
  • 21
  • 33
  • 31
    I've made an extensions for this in case you still need it : https://marketplace.visualstudio.com/items?itemName=sohamkamani.code-eol – Soham Kamani Feb 17 '18 at 11:47
  • 1
    @SohamKamani Your comment should be the accepted answer to the question. – Nicolas Seiller Jul 11 '18 at 09:40
  • That extension is useless: it doesn't actually display whether characters are carriage returns or line feeds, it just makes glyphs at the end of the lines which match what vscode says the file is. It doesn't help pinpoint files with mixed end-of-line styles. (That or vscode is automatically normalizing the files' EOLs, thus making any extension to this effect useless.) – Tustin2121 Oct 26 '18 at 16:32
  • 3
    This has changed: "editor.renderWhitespace": true, true is not accepted anymore. – Timo Jan 01 '21 at 15:43
  • 2
    For "editor.renderWhitespace" valid values: "none", "boundary", "selection", "trailing", "all" as string. – mdiiorio Feb 01 '21 at 08:03

8 Answers8

460

AFAIK there is no way to visually see line endings in the editor space, but in the bottom-right corner of the window there is an indicator that says "CLRF" or "LF" which will let you set the line endings for a particular file. Clicking on the text will allow you to change the line endings as well.

enter image description here

Llewey
  • 8,684
  • 2
  • 26
  • 19
  • 31
    Can you change the default value for this? Right now every time I open a File I have to manually click on this. – David Martinez Oct 26 '16 at 11:31
  • 27
    @DavidMartinez Yes. In user or workspace settings: // The default end of line character. "files.eol": "\r\n", – Llewey Oct 26 '16 at 13:43
  • 5
    @Llewey But this is a global change right? Can I set it somehow only for `.sh` files ? – Kostas Demiris Jun 07 '18 at 08:24
  • @KostasDemiris I haven't tested this but you could try doing `"[sh]": { "files.eol": "\n" }`. Not all settings can be set for a specific language and I'm not sure if this is one that can but it's worth a try. – Michael Dorst Jun 18 '20 at 17:26
  • 12
    Doesn't answer question, which is about displaying the line endings – G Huxley Aug 10 '20 at 02:12
  • Another option to configure line endings in a specific workspace/folder is to add a .editorconfig file (https://editorconfig.org/) and specify desired line ending for all or subset of files. – Safor Nov 18 '20 at 21:10
  • Fortunate, you do not need the mouse to move bottom left to change in file, but `f1` and `change end of line sequence` in the file will do it. – Timo Jul 13 '21 at 10:52
  • Is this what the question was asking? – StayOnTarget Oct 29 '21 at 14:57
137

If you want to set it to LF as default, you can paste this line in your editor settings (F1 menu; > Preferences: Open Settings (JSON))

"files.eol": "\n"

Example:

{
    "git.confirmSync": false,
    "window.zoomLevel": -1,
    "workbench.activityBar.visible": true,
    "editor.wordWrap": true,
    "workbench.iconTheme": "vscode-icons",
    "window.menuBarVisibility": "default",
    "vsicons.projectDetection.autoReload": true,
    "files.eol": "\n"
}

Please note that this will change the default line ending for new files only. This will not edit your files.

deb
  • 6,671
  • 2
  • 11
  • 27
Isak La Fleur
  • 4,428
  • 7
  • 34
  • 50
  • 27
    I've done this, but every time I open a file it still opens with CRLF and I have to manually change it. – pixelwiz Aug 14 '17 at 18:02
  • 1
    @pixelwiz if you save the file does it change to LF? https://github.com/Microsoft/vscode/issues/26626 https://github.com/Microsoft/vscode/issues/2957 I changed to mac, so I do not have this issue anymore when developing on my own projects. So I cant verify, sorry. – Isak La Fleur Sep 08 '17 at 17:12
  • 9
    Same for me on Windows - setting files.eol user settings to "\n" but files are still reported as CLRF – Marko Nov 29 '17 at 08:54
  • Working for me on Windows 7 with VS Code 1.18.0 – ddrake12 Nov 30 '17 at 22:09
  • 2
    I've just tested this successfully with Win 10 and VS Code 1.20.1. New file got created with LF line break! – iaforek Mar 05 '18 at 10:42
  • 1
    On creating new files, they VSCode opens with LF settings. But same as @pixelwiz and for when I open existing files from a project. Ideas how to open existing files with LF as well? – ZenVentzi Mar 07 '20 at 19:24
  • Did anybody come up with the solution for the existing file i.e. how to open an existing file with LF on win10? – HVenom Apr 09 '20 at 10:54
  • Doesn't answer question, which is about displaying the line endings – G Huxley Aug 10 '20 at 02:13
  • Works for new files, the code example is taken from the `settings.json`. You can edit this directly. @IsakLaFleur you should edit your answer to mention the file. – Timo Nov 22 '20 at 20:17
  • It does what it's supposed to do: set default line endings to LF. If you want to bulk-edit your files by replacing the line endings, there must be plenty of ways to do it, I personally use Prettier. – deb Jul 18 '21 at 16:05
76

Render Line Endings is a Visual Studio Code extension that is still actively maintained (as of December 2022):

https://marketplace.visualstudio.com/items?itemName=medo64.render-crlf

https://github.com/medo64/render-crlf/

It can be configured like this:

{
    "editor.renderWhitespace": "all",
    "code-eol.newlineCharacter": "¬",
    "code-eol.returnCharacter" : "¤",
    "code-eol.crlfCharacter"   : "¤¬",
}

and looks like this:

Enter image description here

Kamafeather
  • 8,663
  • 14
  • 69
  • 99
friederbluemle
  • 33,549
  • 14
  • 108
  • 109
26

You can install an extension to show line endings.

There are several available at the VS Marketplace.

Or if their search moves, try this relevant Google search


In the original answer, I had provided a link to a specific extension by Johnny Härtell After two years, this extension and the author are mysteriously missing from the VS Marketplace.

To provide a better experience and hopefully future proof this answer, I've updated it with search results that should keep us pretty close to a relevant extension.

Shanimal
  • 11,517
  • 7
  • 63
  • 76
  • 4
    At present, this extension doesn't do what it purports to. In a file of mixed line endings, it shows line endings as if they were all consistent, based on what VS Code claims the file is following. – Andrew Arnott Jun 17 '19 at 12:40
  • @AndrewArnott thanks for the update, we'll have to watch the issue you've submitted... https://github.com/jhartell/vscode-line-endings/issues/1 – Shanimal Jun 17 '19 at 19:23
  • @AndrewArnott could you tell why it does not work for you?, for me it works perfect, just the icons are small – John Balvin Arias Jul 09 '19 at 05:21
  • @JohnBalvinArias The issue I filed that Shanimal linked to describes the problem: It doesn't actually reveal mixed line endings. It always shows them as if they were consistently whatever VS Code's preference is set to. – Andrew Arnott Jul 10 '19 at 12:49
  • 5
    @AndrewArnott This is because VSCode itself does not support mixed line endings. https://github.com/Microsoft/vscode/issues/127 – CatDadCode Jul 31 '19 at 19:27
  • @AndrewArnott do you know what happened to the plugin? I'm trying to install it again and does not work – John Balvin Arias Jun 24 '21 at 19:55
  • There seems to be a lot of plugins now. I found a small list using google with the following search... I'll update the question shortly. `Line endings site:marketplace.visualstudio.com` – Shanimal Jul 01 '21 at 21:04
5

I used the "find" and simply did a Regex search for "\n". Which seems to show the new lines in a simplistic but useful manner. Hope this helps.

2

Another way to set the default end of line value in Visual Studio Code:

  1. Navigate to the Visual Studio Code settings tab (e.g., by Ctrl + , (comma))
  2. Search for end of line in the search bar
  3. Set the desired value in the Files: Eol dropdown menu

Screenshot:

Enter image description here

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
syntax-punk
  • 3,736
  • 3
  • 25
  • 33
1

Having the opposite problem? How to hide line endings:

Oddly I have the opposite problem! I just ended up with the following highlighting of each newline - which I've never seen before. In all open files and without a selection. Assumed I'd hit a shortcut by mistake, which is how I ended up on this question. Given that the feature doesn't seem to actually exist I resorted to closing and reopening and they went away!

enter image description here

Simon_Weaver
  • 140,023
  • 84
  • 646
  • 689
  • 1
    That's an odd one! I would open user settings json, copy the whole lot into notepad++ (if on windows), then get a copy of the *default* user settings json, also copy the whole lot into notepad++, then reset all the settings in vscode and do a diff on both those to see what changed. Don't suppose you made a separate question so people can actually find your post if they have the same issue? Please link it if you did. – Corné Feb 21 '22 at 20:51
  • No just reopening fixed it by the look of it. So I think VSCode just glitched out. – Simon_Weaver Feb 22 '22 at 04:34
1
  • Ctrl+H
  • Find by "\n"
  • Activate "regular expression" (Alt+R)

enter image description here

Leonardo
  • 120
  • 9