Visual Studio Code: How to show line endings
Asked Answered
V

8

368

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

Vivianne answered 16/9, 2016 at 6:55 Comment(5)
I've made an extensions for this in case you still need it : marketplace.visualstudio.com/…Shwa
@SohamKamani Your comment should be the accepted answer to the question.Parabasis
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.)Shaylyn
This has changed: "editor.renderWhitespace": true, true is not accepted anymore.Ironist
For "editor.renderWhitespace" valid values: "none", "boundary", "selection", "trailing", "all" as string.Kew
H
478

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

Hayward answered 16/9, 2016 at 13:36 Comment(8)
Can you change the default value for this? Right now every time I open a File I have to manually click on this.Zinciferous
@DavidMartinez Yes. In user or workspace settings: // The default end of line character. "files.eol": "\r\n",Hayward
@Hayward But this is a global change right? Can I set it somehow only for .sh files ?Milliard
@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.Earreach
Doesn't answer question, which is about displaying the line endingsPlaton
Another option to configure line endings in a specific workspace/folder is to add a .editorconfig file (editorconfig.org) and specify desired line ending for all or subset of files.Wiebmer
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.Ironist
Is this what the question was asking?Waddle
R
141

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.

Rosenstein answered 7/3, 2017 at 8:38 Comment(10)
I've done this, but every time I open a file it still opens with CRLF and I have to manually change it.Fulminant
@Fulminant if you save the file does it change to LF? github.com/Microsoft/vscode/issues/26626 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.Rosenstein
Same for me on Windows - setting files.eol user settings to "\n" but files are still reported as CLRFBirkle
Working for me on Windows 7 with VS Code 1.18.0Bizarre
I've just tested this successfully with Win 10 and VS Code 1.20.1. New file got created with LF line break!Ilse
On creating new files, they VSCode opens with LF settings. But same as @Fulminant and for when I open existing files from a project. Ideas how to open existing files with LF as well?Modal
Did anybody come up with the solution for the existing file i.e. how to open an existing file with LF on win10?Te
Doesn't answer question, which is about displaying the line endingsPlaton
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.Ironist
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.Gladiator
T
82

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

Tsarism answered 22/4, 2020 at 0:57 Comment(2)
I'm getting "unknown configuration setting"Egocentrism
@JohnBalvinArias Did you install the extension?Tsarism
P
27

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.

Putumayo answered 7/12, 2018 at 5:34 Comment(7)
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.Assault
@AndrewArnott thanks for the update, we'll have to watch the issue you've submitted... github.com/jhartell/vscode-line-endings/issues/1Putumayo
@AndrewArnott could you tell why it does not work for you?, for me it works perfect, just the icons are smallEgocentrism
@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.Assault
@AndrewArnott This is because VSCode itself does not support mixed line endings. github.com/Microsoft/vscode/issues/127Hellkite
@AndrewArnott do you know what happened to the plugin? I'm trying to install it again and does not workEgocentrism
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.comPutumayo
H
8

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.

Hegelian answered 11/4, 2022 at 15:48 Comment(0)
S
4
  • Ctrl+H
  • Activate "regular expression" (Alt+R)
  • Find by "\n"

enter image description here

See answered 5/4, 2023 at 14:17 Comment(1)
Perfect, underrated answer!\n Thanks!Niello
T
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

Tocci answered 27/8, 2021 at 3:55 Comment(2)
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.Lineal
No just reopening fixed it by the look of it. So I think VSCode just glitched out.Tocci
F
0

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

Frederic answered 4/3, 2021 at 15:19 Comment(1)
The question was how to display the current line ending, not how to change it.Hollow

© 2022 - 2024 — McMap. All rights reserved.