Skip to content

Instantly share code, notes, and snippets.

@jandudulski
Last active August 10, 2020 10:31
Show Gist options
  • Save jandudulski/4451806 to your computer and use it in GitHub Desktop.
Save jandudulski/4451806 to your computer and use it in GitHub Desktop.
How to configure your editor to automatically strip trailing whitespaces and keep new line at the end of file?
if has("autocmd")
" remove trailing white spaces
autocmd BufWritePre * :%s/\s\+$//e
endif
* Tools -> Options -> Editor -> On Save > Remove Trailing Whitespace From
* Select: All lines
Go to preferences / editor and check:
* Ensure line feed at file end on Save
* Strip trailing spaces on Save
// Trims white space added by auto_indent when moving the caret off the line.
"ensure_newline_at_eof_on_save": true,
"trim_automatic_white_space": true
"files.insertFinalNewline": true,
"files.trimTrailingWhitespace": true
@rossinek
Copy link

VS Code (settings.json)

"files.insertFinalNewline": true,
"files.trimTrailingWhitespace": true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment