Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I selectively trim trailing whitespace in VSCode?

I generally have the Trim Trailing Whitespace setting turned on in VSCode because I want that behaviour for code files.

However, I have a folder of text resources (.txt files) that I would like to exclude from this rule. Some of the text files need trailing whitespace on the lines.

Is it possible to selectively turn this rule on/off based on file path or file extension?

I've tried having a .vscode/settings.json file at the root of my workspace turning the feature on, and another in the folder containing the text resources to turn it off and that doesn't work.

Is there an extension that enables this? I looked but wasn't able to find one.

like image 630
Andrew Cooper Avatar asked Sep 12 '25 15:09

Andrew Cooper


1 Answers

In settings.json, insert:

"[plaintext]": {
    "files.trimTrailingWhitespace": false
}
like image 99
connexo Avatar answered Sep 14 '25 08:09

connexo