Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Code, Fold Comments

Visual Studio Code 1.24.1

While I was working on something today. It prompted me to do an update which I did (Update was to 1.24.1). I'm not sure if I hit a shortcut accidentally at about this same time or if this was caused by the update.

But I seem to no longer be able to use comments as a fold point.

However again, I'm not sure if I hit a shortcut of some sort, or if this was caused by the patch.

and my googlefu did not help me find an answer for visual studio code. Found many old topics about visual studio (prof not code) and for other editors. but couldn't find a topic specific to VSC.

I liked to use comments as fold points \ section headers.

Example of comments I used to use as fold points

Is this a bug in VSC 1.24.1 or did I hit a shortcut I'm unaware of?

like image 510
James Avatar asked Jul 02 '18 15:07

James


People also ask

How do you collapse comments in VSCode?

CTRL + M + M will collapse/expand the current section. CTRL + M + A will collapse all even in Html files.

How do you wrap text in VSCode?

wordWrap": "on" You can toggle word wrap for the VS Code session with ⌥Z (Windows, Linux Alt+Z).

How do you comment multiple lines of code at once?

To comment out multiple code lines right-click and select Source > Add Block Comment. ( CTRL+SHIFT+/ ) To uncomment multiple code lines right-click and select Source > Remove Block Comment. ( CTRL+SHIFT+\ )


1 Answers

VS Code has a method of marking the start and end of a region that can be folded and expanded easily. And also provide it a name/short description that'll always be visible.

I've tried this on Javascript code and I believe it'll work on any language in VS Code. And you can have anything in between the start and end of region - comments, few lines or code, entire functions.

In the absence of proper code folding, this is a pretty good work around that'll work for all languages on VS Code.

//#region <REGION NAME>

      < You can put any type of code in here - some lines of code, functions or single or multi-line comments.
//#endregion

For python, simply omit the // in the demarcation lines, since # is a valid comment indicator:

#region <REGION NAME>
...
# any code goes here, including multiple comment lines
...
#endregion
like image 119
Curious101 Avatar answered Nov 25 '22 02:11

Curious101