Fold function in vim

前端 未结 5 1661
無奈伤痛
無奈伤痛 2021-01-29 18:21

Is there any way or tools to fold function in vim, like Visual Studio or Eclipse?

5条回答
  •  渐次进展
    2021-01-29 18:24

    Yes. VIM has exceptional folding capabilities. I don't like learning too many controls, I prefer automation, so here is what I personally use:

    In my .vimrc:

    set foldmethod=indent
    set foldlevel=1
    set foldclose=all
    

    This automatically folds files that you open, based on indent, for everything indented for more than 1 level. The foldclose option makes the fold automatically re-close after I navigate out of the fold.

    In-file Controls:

    zo - opens folds
    zc - closes fold
    zm - increases auto fold depth
    zr - reduces auto fold depth
    

    And if you ever get annoyed with the folds, use

    : set foldmethod=syntax
    

    or press:

    zR
    

    to make them all go away.

提交回复
热议问题