Visual Studio Code — 在文件末尾插入新行 [英] Visual Studio Code — Insert New Line at the End of Files
问题描述
在使用 Visual Studio Code 保存文件时,我注意到新行不会自动添加到文件末尾,从而导致各种潜在问题.
When saving files using Visual Studio Code, I noticed that a new line is not automatically added to the end of files, causing all sorts of potential issues.
如何在 Visual Studio Code 中自动插入新行?
How does one insert a new line automatically in Visual Studio Code?
推荐答案
有两种简单的方法可以让 Visual Studio Code 在文件末尾插入新行:
There are two easy methods to make Visual Studio Code insert a new line at the end of files:
打开 Visual Studio Code 并转到文件(如果使用 Mac 则为代码)-> 首选项 -> 设置;您现在应该正在查看设置页面
Open Visual Studio Code and go to File (Code if using a Mac) -> Preferences -> Settings; you should now be viewing a settings page
在搜索栏中输入插入最终换行符"
在工作区设置"和/或用户设置"中选中标题文件:插入最终换行符"下的复选框强>'标签(s)根据需要
Select the checkbox under the heading 'Files: Insert Final Newline' in the 'Workspace Settings' and/or 'User Settings' tab(s) as required
打开 Visual Studio Code 并转到文件(如果使用 Mac 则为代码)-> 首选项 -> 设置;您现在应该正在查看设置页面
Open Visual Studio Code and go to File (Code if using a Mac) -> Preferences -> Settings; you should now be viewing a settings page
点击页面右上角的{}图标打开 JSON 设置页面
Open the JSON settings page by clicking the {} icon at the top right of the page
在 JSON 设置页面的搜索栏中输入files.insertFinalNewline"
Enter 'files.insertFinalNewline' in to the search bar of the JSON settings page
要么
- 单击包含
files.insertFinalNewline
JSON 键的行左侧的白色编辑笔",然后选择True
- Click on the white 'edit pen' on the left hand side of the line containing the
files.insertFinalNewline
JSON key and selectTrue
或
- 复制包含
files.insertFinalNewline
JSON 密钥的行,将其粘贴到 '用户设置' 和/或 ' 下的右侧 JSON 文件中根据需要工作区设置'选项卡,并将其值设置为true
- Copy the line containing the
files.insertFinalNewline
JSON key, paste it into the right hand side JSON file under the 'User Settings' and/or 'Workspace Settings' tab(s) as required, and set its value totrue
在您的用户设置或工作区设置 JSON 文件中,您应该有一行读取 "files.insertFinalNewline": true
,在提供的花括号 ({}).此外,在设置页面中,将选中标题文件:插入最终换行符"下的复选框.
In either your User Settings or Workspace Settings JSON file, you should have a line reading "files.insertFinalNewline": true
, within the provided curly braces ({ }). Additionally, in the Settings page, the checkbox under the heading 'Files: Insert Final Newline' will be selected.
Visual Studio Code 现在会在保存文件时在文件末尾添加一个空行(如果还没有空行).
Visual Studio Code will now add an empty line to the end of files when being saved, if there isn't already one.
这篇关于Visual Studio Code — 在文件末尾插入新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!