Reputation: 2147
Code folding in VScode doesn't seem as good as IntelliJ's.
eg. code block
def g(a):
print(a)
print(a)
print(a)
print(a)
print(a)
Or, for (...),{...},[...] (indentation isn't actually the real concern.)
eg code sample from dart(flutter):
OutlinedButton(
onPressed: () {
Navigator.pushNamed(
context,
SecondPage.id,
);
},
child: Text("Page 2"),
)
Upvotes: 0
Views: 1366
Reputation: 767
Three points. Two addressed by others already but I'll include them here for completeness, with the third being my own contribution.
As per daiyam's answer, press Shift+Down
at the start of the folded code to select everything between it and the next visible line. This then includes all the folded code, which you can then copy/paste.
My own contribution here: Similarly, to add a new line after the folded code, either press Down
from the start of the folded code line, or press Right
from the end of that line, to get to the start of the next line. Then press Enter
to add a new line there. Then Up
to get to the start of the new line.^^
Editor: Show Folding Controls
to always
.^^ Some potentially overkill analysis 😉 ...
Yes, that seems like a lot of steps for something you're used to doing in one step in IntelliJ, except it's only two extra (arrow) key presses. If you're switching away from IntelliJ, to Code, then your muscle memory will likely adapt pretty quick. That might only be a problem if you're switching back and forth between them frequently.
Also, whatever keys or mouse click you've done to get to the start or end of that first folding line in the first place could be replaced by a different click or key presses to get you to the start of that next line instead. So the only extra really is the Up
key after the Enter
, plus the (presumably pretty tiny) learning curve to remember to go to that next line start instead of previous line end.
I suppose if that's a big deal, you could use any of the Macro applications to combine those extra arrow keystrokes and the Enter
to one keystroke (say Shift+Enter
or something). I find myself doing that sort of thing a lot to bring consistency to my use of different IDE's etc.
Just a couple of ideas in case they help.
Upvotes: 1
Reputation: 21
I'm assuming that the code language is Python.
So, now if I fold this code and try to duplicate the folded line, it doesn't copy the entire fold as it does in IntelliJ
You need to select the whole region. To do that, simply do a Shift+Down
, then you can copy/paste the region.
If I press Enter after folding, it creates a new line in the folding section, I actually want it to create the line after the folding section.
Python's folding regions are based on the indentation. So when pressing Enter
after a folding, the new line is tabbed so it is inside the region. You need to delete the tab so the line isn't in the region.
Finish code folding in one line
To fold on a single line, you need to use the extension Explicit Folding and the following configuration:
"[python]": {
"explicitFolding.rules": [
{
"beginRegex": "\"\"\"",
"endRegex": "\"\"\"",
},
{
"indentation": true,
"offSide": true
}
]
}
Upvotes: 2