A Visual Studio Code extension that removes final newlines on save.
CMD + Shift + P -> Remove Final Newlines: Format document and remove final newlines
Respects files.insertFinalNewline
setting.
Enable or disable by setting files.removeFinalNewlines
(default: false
) in Visual Studio Code configuration.
{
"files.removeFinalNewlines": true
}
The setting files.removeFinalNewlines
can be overridden by language specific settings:
. . .
"files.insertFinalNewline": false,
"files.removeFinalNewlines": true,
"files.trimFinalNewlines": false,
"files.trimTrailingWhitespace": true,
"[markdown]": {
"files.insertFinalNewline": true,
"files.removeFinalNewlines": false,
"files.trimFinalNewlines": true,
"files.trimTrailingWhitespace": false
},
. . .
Use the following shortcut in keybindings.json to execute the default Format Document command and then remove final newlines. Replace with your preferred key bindings.
{
"command": "removeFinalNewlines.formatAndRemoveFinalNewlines",
"key": "alt+f",
"when": "editorTextFocus && !editorReadonly"
}
Licensed under the MIT License.