11
votes

I am working on some fairly large files in Visual Studio code and to save time I fold away functions and scopes, that I do not want to see. Everytime I save, which I do fairly often just out of habit, all the folds expand again and the current position on screen changes.

Since the only settings I could find were:

"editor.folding": true,
"editor.showFoldingControls": "mouseover",

the question is: How can I keep my folds upon saving?

4
I wonder if you have another setting or extension that conflicts with vscode's folding because my folds are saved and reused, even when restarting vscode.Mark
That's odd. At home it works. I need to double check this in the office tomorrow. Maybe its related to the fact, that at work I'm working on files located on a network share.Marco

4 Answers

10
votes

Thank you for bringing up the extensions Mark. It was indeed an extension: lonefy.vscode-js-css-html-formatter.

Once this was disabled, the folding kept its state after saving.

3
votes

Had the same issue and it turned out to be the sort-imports extension. Removing it fixed the issue.

3
votes

For me it was the prettier plugin :(

Here is the closed issue: https://github.com/prettier/prettier-vscode/issues/408.

At the moment, there doesn't seem to be a fix.

1
votes

For anyone that comes across this like me, I didn't have prettier, sort-imports, or lonefy. I was able to resolve by updating the 'folding strategy' setting from 'auto' to 'indentation' and it kept my folds persistent through saving and particularly in my case deploying code using the Salesforce CLI extension.