1
- *fold.txt* For Vim version 9.0. Last change: 2022 Jan 22
1
+ *fold.txt* For Vim version 9.0. Last change: 2022 Oct 01
2
2
3
3
4
4
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -74,8 +74,6 @@ method. The value of the 'foldexpr' option is evaluated to get the foldlevel
74
74
of a line. Examples:
75
75
This will create a fold for all consecutive lines that start with a tab: >
76
76
:set foldexpr=getline(v:lnum)[0]==\"\\t\"
77
- This will call a function to compute the fold level: >
78
- :set foldexpr=MyFoldLevel(v:lnum)
79
77
This will make a fold out of paragraphs separated by blank lines: >
80
78
:set foldexpr=getline(v:lnum)=~'^\\s*$'&&getline(v:lnum+1)=~'\\S'?'<1':1
81
79
This does the same: >
@@ -84,6 +82,10 @@ This does the same: >
84
82
Note that backslashes must be used to escape characters that ":set" handles
85
83
differently (space, backslash, double quote, etc., see | option-backslash | ).
86
84
85
+ The most efficient is to call a compiled function without arguments: >
86
+ :set foldexpr=MyFoldLevel()
87
+ The function must use v:lnum. See | expr-option-function | .
88
+
87
89
These are the conditions with which the expression is evaluated:
88
90
- The current buffer and window are set for the line.
89
91
- The variable "v:lnum" is set to the line number.
@@ -501,7 +503,7 @@ is evaluated to obtain the text displayed for a closed fold. Example: >
501
503
502
504
This shows the first line of the fold, with "/*", "*/" and "{{{" removed.
503
505
Note the use of backslashes to avoid some characters to be interpreted by the
504
- ":set" command. It's simpler to define a function and call that : >
506
+ ":set" command. It is much simpler to define a function and call it : >
505
507
506
508
:set foldtext=MyFoldText()
507
509
:function MyFoldText()
@@ -510,6 +512,9 @@ Note the use of backslashes to avoid some characters to be interpreted by the
510
512
: return v:folddashes .. sub
511
513
:endfunction
512
514
515
+ The advantage of using a function call without arguments is that it is faster,
516
+ see | expr-option-function | .
517
+
513
518
Evaluating 'foldtext' is done in the | sandbox | . The current window is set to
514
519
the window that displays the line. The context is set to the script where the
515
520
option was last set.
0 commit comments