8

In Visual Studio Code the setting

"files.trimTrailingWhitespace": true

removes trailing white space when files are saved, or Shift + Alt + F is used to format a file, but this breaks Markdown formatting.

How do you selectively turn off white space trimming for Markdown?

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
GollyJer
  • 18,860
  • 14
  • 91
  • 148

3 Answers3

23

Add this line to your settings.json file.

"[markdown]": {
    "files.trimTrailingWhitespace": false
}
GollyJer
  • 18,860
  • 14
  • 91
  • 148
  • How can I additionally turn it off for `text (.txt)` and `csv` files? – Superdooperhero Dec 28 '19 at 18:07
  • 1
    `ctl-k m` to bring up the language mode selector. That is the list of language specific settings you can apply. For text it looks like `[plaintext]`. [This could be helpful to set csv files to behave like plain text files](https://stackoverflow.com/a/36789145/25197). – GollyJer Dec 30 '19 at 20:04
  • Thanks! CSV does not seem to be in the list though. – Superdooperhero Dec 30 '19 at 20:12
  • 1
    Yeah. Use the link provided in my last comment to make csv format like text. – GollyJer Dec 30 '19 at 21:02
3

You can use EditorConfig by adding .editorconfig at the root of your project:

[!markdown]
trim_trailing_whitespace: false

Or as GollyJer suggested, add this code snippet in the settings.json file:

"[markdown]": {
    "files.trimTrailingWhitespace": false
}
Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
Yashu Mittal
  • 1,208
  • 2
  • 10
  • 31
0

Do Ctrl-K s. This will "Save without formatting", which also means, without trimming trailing whitespace in the file you're editing

kolypto
  • 27,502
  • 15
  • 92
  • 90