can we specify multiple foldmarkers in vim?

Viewed 91

I am trying to fold multiple lines in vim with :set foldmethod=marker I have done :set foldmarker={,} is there any way such that we can fold function that has starting braces='[' and end braces=']' and also fold a function with starting braces='{' and end braces='}' like in vscode we can fold any function with any starting and ending braces.

1 Answers

From :help folding:

There are six methods to select folds:
    manual      manually define folds
    indent      more indent means a higher fold level
    expr        specify an expression to define folds
    syntax      folds defined by syntax highlighting
    diff        folds for unchanged text
    marker      folds defined by markers in the text
  • marker won't help for the reason given under :help 'foldmarker':

    The marker is a literal string (a regular expression would be too slow).
    

    See :help fold-marker.

  • diff is irrelevant.

    See :help fold-diff.

  • syntax may help, depending on the language and how the syntax script for that language was written.

    See :help fold-syntax.

  • expr is the most powerful method because it lets you decide exactly what to fold and how to fold it.

    It is also the hardest to set up, for obvious reasons. See :help fold-expr.

  • indent is a pretty dumb method, which makes it very memory efficient and versatile. You could try that one because it doesn't care about braces at all.

    See :help fold-indent.

  • And then there is the manual method, which lets you define folds with motions.

    This lets you do things like zfi{ or zf12j.

    See :help fold-manual.

Related