Home > Enterprise >  How can I selectively trim trailing whitespace in VSCode?
How can I selectively trim trailing whitespace in VSCode?

Time:07-25

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.

CodePudding user response:

In settings.json, insert:

"[txt]": {
    "files.trimTrailingWhitespace": false
}
  • Related