VS Code Force Newline at End of File

In software development it’s generally considered good practice (and sometimes necessary) to add a blank line at the end of a code file. In VS Code we can configure the IDE to force a newline at the end of a file every time we save. There are several ways to set this up, as discussed below.

Global Settings

To apply a newline at file end for any file saved in the IDE, open VS Code and:

Navigate to File (‘Code’ on Mac) > Preferences > Settings.

In the search bar, type Insert Final Newline. You should see a single setting appear, where you can check the box to activate this functionality.

Project Settings

If your project is using a dedicated settings file at .vscode/settings.json, you can add the line “files.insertFinalNewline”: true within the settings JSON object in this file. Adding this line should apply a newline to the end of any file in the project when saving.

the author profile picture

Ryan Neilson is a software developer from Nova Scotia, Canada, where he lives with his wife and their menagerie of pets. He has worked extensively with PHP, WordPress, JavaScript, React, SCSS and CSS. Ryan can be found professionally at News Corp, where he works as a lead software engineer.