VS Code & Markdown

Prevent VS Code from trimming trailing whitespace in markdown files

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:

  1. Open the Command Palette (View, Command Paletteā€¦. or CTRL+SHIFT+P)
  2. Select Preferences: Open Settings (JSON)
  3. Add the snippet:
    "[markdown]": {
        "files.trimTrailingWhitespace": false
    }
    
  4. Save settings.json
Built with Hugo
Theme Stack designed by Jimmy