Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
591 views
in Technique[技术] by (71.8m points)

text editor - How do you hide arbitrary section of code in VS Code?

By "VS Code" I mean the lightweight text editor not the monolithic IDE, unfortunately searching this on google will bring up many pieces of irrelevant information about how to do this in Visual Studio.

To the question itself, Anybody knows how to hide arbitrary selected lines of code in "Visual Studio Code", preferably into a plus sign like collapsing does?

Note: this is different than collapsing nested code which probably could be achieved by Ctrl+K,Ctrl+<num> , what I need here is to hide specific block of code of choice, no matter nested or not.

EDIT: I see there are people who don't understand my requirements.

for example, you may think what I want is this:

before hiding:

for i in j:
    for k in i:
        for l in k:
            somestuff...

after hiding:

[+] for i in j: ...

What I actually want is this:

before hiding:

# doing stuff about a
a = ClassA()
a.bar()
a.i = 2
a.j = 3
a.k = 5

after hiding:

[+] ...  ( doing stuff about a )

2017.10.17 EDIT: turns out VS Code implemented a very similar feature called "Folding Regions" in VS Code 1.17.1 Update. link

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use the following delimiters for code folding:

C/C++:       #pragma region and #pragma endregion
C#:          #region and #endregion
CSS:         /* #region */ and /* #endregion */
Java:        //region and //endregion
JavaScript:  //#region and //#endregion and //region and //endregion
PHP:         #region and #endregion
Powershell:  #region and #endregion
Python:      #region and #endregion
VB:          #Region and #End Region

See https://github.com/Microsoft/vscode/issues/12146 ([folding] fold regions)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...