Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to keep code-folding on save in Visual studio code

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?

like image 723
Marco Avatar asked Nov 16 '17 09:11

Marco


People also ask

How do I keep my VS Code always on top?

Once you've opened Visual Studio Code, just press alt + space and the system menu will appear, then you just have to select the Always on top option.

How do you keep indentation code in Visual Studio?

Hit Tab multiple times until your cursor is at the proper indentation. Navigate up to a line with proper indentation, press End , then press Enter . Click your mouse to the right of a properly indented line, then press Enter . Press Ctrl + ] repeatedly to indent the empty line.

How do I get Visual Studio to auto save code?

To turn on or turn off the Auto Save feature in Visual Studio Code, go to File and click on Auto Save from the drop-down menu: The steps are completely the same in Windows and macOS. If you want to config the Auto Save behavior deeper, go to: Mac: Code > Preferences > Settings.


Video Answer


4 Answers

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.

like image 60
protoEvangelion Avatar answered Oct 10 '22 21:10

protoEvangelion


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.

like image 26
Donovan Dacons Avatar answered Sep 20 '22 14:09

Donovan Dacons


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.

like image 10
Marco Avatar answered Oct 10 '22 23:10

Marco


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

like image 3
Matt MacPherson Avatar answered Oct 10 '22 22:10

Matt MacPherson