Skip to content

A Visual Studio Code extension that removes final new lines on save

License

Notifications You must be signed in to change notification settings

DoCode/vscode-remove-final-newlines

Repository files navigation

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

Format On Save

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.

About

A Visual Studio Code extension that removes final new lines on save

Resources

License

Stars

Watchers

Forks

Packages

No packages published