Remove Final Newlines
A Visual Studio Code extension that removes final newlines on save.
Usage
Using Command Palette (CMD/CTRL + Shift + P)
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
},
. . .
Custom Keyboard Shortcut
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"
}
License
Licensed under the MIT License.