When saving a file using Visual Studio Code, a newline is not automatically added to the end of the file, causing all sorts of potential issues .
How can I append a newline automatically in Visual Studio Code?
There are two easy methods to make Visual Studio Code insert a new line at the end of files:
Open Visual Studio Code and go to File (Code if using a Mac) -> Preferences -> Settings ; you should now be viewing a settings page
Enter ' insert final newline ' in to the search bar
Select the checkbox under the heading ' Files: Insert Final Newline ' in the ' Workspace Settings ' and/or ' User Settings ' tab(s) as required
Open Visual Studio Code and go to File (Code if using a Mac) -> Preferences -> Settings ; you should now be viewing a settings page
Open the JSON settings page by clicking the {} icon at the top right of the page
Enter ' files.insertFinalNewline ' in to the search bar of the JSON settings page
Either
files.insertFinalNewline
JSON key and select True
or
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 to 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 will now add an empty line to the end of files when being saved, if there isn't already one.
I was experiencing the same issue and solved it by uninstalling a save while typing extension that I had installed.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.