VS Code automatically trims any trailing whitespace in a file, which makes sense for a lot of formats, but in markdown, a double trailing whitespace has special meaning - it acts as a LF
and creates a line break without a hard return (CRLF
).
This automatic trim also occurs when formatting a file according to the language’s rules.
Let’s configure VS Code to continue automatically trimming trailing whitespace, except for markdown files:
- Open the Command Palette (View, Command Paletteā¦. or CTRL+SHIFT+P)
- Select
Preferences: Open Settings (JSON)
- Add the snippet:
"[markdown]": { "files.trimTrailingWhitespace": false }
- Save
settings.json