I've been using Visual Studio Code version 1.74.3 on Windows 10 to take all my math notes. So my txt file is mainly composed of the following structure:
[Theorem]
[Indentation] Proof:
[Indentation] [Indentation] [Proof per see]
Here is an example: https://i.sstatic.net/0vBIn.jpg
I want to fold all the groups of lines that start with the word "Proof" (it occurs 3454 times as of now) because most of the time I don't need to see it, and they're usually quite lengthy. I want to collapse all the lines immediately below each Proof line that share the same indentation. It's also the case that every proof ends with the character "∎".
The problem is that the file is very long (75k lines) and subdivided into many different regions with different indentation levels, so I cannot just use the "Fold by level K" option, since not all proofs are at the same level.
Therefore, folding all the lines that start with the word "Proof" seems to be the way to go.
I've read the section https://code.visualstudio.com/docs/editor/codebasics#_folding for a way to fold all the lines that start with the word "Proof", but I couldn't find any.
Does anyone know how to do it, or have any other suggestion?
Thanks in advance! :-)
This can be done thanks to the command editor.createFoldingRangeFromSelection which will fold anything you can select. It looks like this find would select each of your proof-groups:
^[\t ]*Proof[\s\S\n]*?∎ // I didn't thoroughly test this
So you could (1) find those using the Find Widget, then
(2) Alt+Enter (the editor.action.selectAllMatches command will select each find match separately) and then
(3) Ctrl+k Ctrl+, to apply the editor.createFoldingRangeFromSelection command and it should fold each of those find matches.
To automate this a bit, you can use an extension I wrote, Find and Transform, and this keybinding (in your keybindings.json):
{
"key": "alt+c", // whatever keybinding you want
"command": "findInCurrentFile",
"args": {
"find": "^[\\t ]*Proof[\\s\\S\n]*?∎", // need double-escaping here
"isRegex": true,
"postCommands": [
"editor.action.selectAllMatches",
"editor.createFoldingRangeFromSelection"
]
},
"when": "editorTextFocus && !editorReadonly && editorLangId == plaintext"
}
It does the same find, separately selects each match and then folds it.

The command Remove Manual Folding Ranges will unfold any selected manually folded range. So if you wanted to unfold all your proof-ranges at once, this keybinding would work:
{
"key": "alt+d", // whatever keybinding you want
"command": "findInCurrentFile",
"args": {
"find": "^[\\t ]*Proof[\\s\\S\n]*?∎",
"isRegex": true,
"postCommands": [
"editor.action.selectAllMatches",
"editor.removeManualFoldingRanges"
]
},
"when": "editorTextFocus && !editorReadonly && editorLangId == plaintext"
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With