如何在 VS Code 中隐藏任意代码段? [英] How do you hide arbitrary section of code in VS Code?

查看:97
本文介绍了如何在 VS Code 中隐藏任意代码段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我所说的VS Code"是指轻量级文本编辑器,而不是单一的 IDE,不幸的是,在谷歌上搜索它会带来许多关于如何在 Visual Studio 中执行此操作的无关信息.

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.

对于问题本身,任何人都知道如何在Visual Studio Code"中隐藏任意选定的代码行,最好像折叠一样隐藏在加号中?

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?

注意:这与折叠嵌套代码不同,它可能可以通过 Ctrl+K,Ctrl+ 实现,我在这里需要是隐藏选择的特定代码块,无论是否嵌套.

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.

我发现有些人不理解我的要求.

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

例如,您可能认为我想要的是:

隐藏前:

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

隐藏后:

[+] for i in j: ...

我真正想要的是:

隐藏前:

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

隐藏后:

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

2017.10.17 结果 VS Code 在 VS Code 1.17.1 更新中实现了一个非常相似的功能,称为折叠区域".链接

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

推荐答案

您可以使用以下分隔符进行代码折叠:

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

参见 https://github.com/Microsoft/vscode/issues/12146([折叠] 折叠区域)

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

这篇关于如何在 VS Code 中隐藏任意代码段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆