Visual Studio Code — Insert New Line at the End of Files

后端 未结 2 496
小鲜肉
小鲜肉 2021-01-30 19:32

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.

How does one

2条回答
  •  醉梦人生
    2021-01-30 19:51

    There are two easy methods to make Visual Studio Code insert a new line at the end of files:

    Method I

    1. Open Visual Studio Code and go to File (Code if using a Mac) -> Preferences -> Settings; you should now be viewing a settings page

    2. Enter 'insert final newline' in to the search bar

    3. Select the checkbox under the heading 'Files: Insert Final Newline' in the 'Workspace Settings' and/or 'User Settings' tab(s) as required

    Method II

    1. Open Visual Studio Code and go to File (Code if using a Mac) -> Preferences -> Settings; you should now be viewing a settings page

    2. Open the JSON settings page by clicking the {} icon at the top right of the page

    3. Enter 'files.insertFinalNewline' in to the search bar of the JSON settings page

    4. Either

      • Click on the white 'edit pen' on the left hand side of the line containing the files.insertFinalNewline JSON key and select True

      or

      • 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 to true

    Final Result

    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.

提交回复
热议问题