视觉工作室代码: 如何显示行尾
原标题:Visual Studio Code: How to show line endings
在视觉工作室代码( 不在视觉工作室) 中, 我如何能够显示线条( CR, LF)? 目前只有小状态栏菜单显示/ 更改线条如果实际文件的话结束的线条 。 但有时看到行条条条条条条条条条直接结束会很好, 特别是当有混合行条条条尾时( 情况不好, 但这种情况经常发生 ) 。 我使用以下设置, 但没有一个设置显示线条结尾 。 “ 编辑. renderWhitespace ” : 真实的, “ 编辑. render ControlCharacters ” : 真实的, “ 编辑. renderindGuides ” : 是否设置线条条条线条? 我在 GitHub 上打开了一个问题: 在 # 12223 Soham Kamani 文本区域显示线条尾的可能性 。 “ 代码- eol”
问题回答
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.
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": "
"
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": "
"
}
Please note that this will change the default line ending for new files only. This will not edit your files.
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:
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.
I used the "find" and simply did a Regex search for "
". Which seems to show the new lines in a simplistic but useful manner. Hope this helps.
Ctrl+H
Activate "regular expression" (Alt+R)
Find by "
"
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!
Another way to set the default end of line value in Visual Studio Code:
Navigate to the Visual Studio Code settings tab (e.g., by Ctrl + , (comma))
Search for end of line in the search bar
Set the desired value in the Files: Eol dropdown menu
Screenshot:
VS Code has normalized line endings since at least since 2015:
The current file model normalizes the line endings as soon as the file is read (i.e. each line does not keep track of its EOL), the model only keeps track of one EOL for the entire file (which is computed on file open as the predominantely used EOL character).
... Before we invest a lot into supporting this, when is it desirable to have a file with code that uses mixed EOL sequences? (i.e. why would you want to have a mixed EOL file at all)
It is, therefore, not possible to open a file with mixed line endings - VS Code will silently "fix" the line endings for you.
While there are plugins that will reveal the line ending, those plugins are not able to override that core behavior and will thus effectively just show you the line endings you have configured for your project (or the default line endings chosen automatically by VS Code).
As evidence, see this review on the popular Render Line Endings plugin by Josip Medved, with acknowledgement from the author:
"It shows line endings, as if they were all consistently what VS Code s setting was for that file. For a file with mixed endings, it just renders the default symbol for every line ending regardless, making it useless to perceive the differences in line endings throughout the file." -- Andrew Arnott
"This is unfortunatelly a known issue. ... Visual Studio Code normalizes the line endings upon load and thus this it isn t possible to have multiple different line endings." -- Josip Medved