Sublime Text: Hide all code and show only comments

房东的猫 提交于 2019-12-11 13:03:47

问题


I find it tedious to manage very large style sheets in Sublime Text 3.

Some of my stylesheets are about 2000 lines of code. I am trying to figure out how to navigate more easily within the stylesheet. I already know about bookmarks and the brilliant search function, but another way would be to hide/fold all code and show comments only. Tis way it would be easier to find the correct place you want to go to.

So is there a way to hide all code below a comment? This would be something as the opposite of Fold Comments

I know Hugo proposed the classic "fold all" solution here. But I would like to hide absolutely all code and display comments only.

For example:

/*******************************************************************
Description 1
*******************************************************************/

Hide/fold all code between here...
...
...
..
.
.

/*******************************************************************
Description 2
*******************************************************************/

回答1:


You can fold everything, which is not a comment by opening the console ctrl+` and write view.fold(view.find_by_selector("-comment")). This searches all regions with the selector - comment, which means everything except comments. Afterwards these regions are folded.

If you want to create a keybinding for it, just create a plugin. Open Tools >>> Developer >>> New Plugin and paste:

import sublime_plugin


class FoldEverythingExceptCommentsCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        regions = self.view.find_by_selector("-comment")
        self.view.fold(regions)

Afterwards add this to your Key Bindings - User to add a keybinding for the command:

{
    "keys": ["ctrl+alt+shift+f"],
    "command": "fold_everything_except_comments"
},



回答2:


You can use the arrows in the far left of the text editor. Sublime has the line number listed down the left and beside those numbers are tiny arrows.



来源:https://stackoverflow.com/questions/37282130/sublime-text-hide-all-code-and-show-only-comments

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!