Mercurial > vim
annotate runtime/doc/fold.txt @ 28871:18604231a1d1 v8.2.4958
patch 8.2.4958: a couple conditions are always true
Commit: https://github.com/vim/vim/commit/dd41037552c1be3548d2ce34bb1c889f14edb553
Author: =?UTF-8?q?Dundar=20G=C3=B6c?= <gocdundar@gmail.com>
Date: Sun May 15 13:59:11 2022 +0100
patch 8.2.4958: a couple conditions are always true
Problem: A couple conditions are always true.
Solution: Remove the conditions. (Goc Dundar, closes https://github.com/vim/vim/issues/10428)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 15 May 2022 15:00:02 +0200 |
parents | d19b7aee1925 |
children | f8116058ca76 |
rev | line source |
---|---|
27321 | 1 *fold.txt* For Vim version 8.2. Last change: 2022 Jan 22 |
7 | 2 |
3 | |
4 VIM REFERENCE MANUAL by Bram Moolenaar | |
5 | |
6 | |
2033
de5a43c5eedc
Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
1702
diff
changeset
|
7 Folding *Folding* *folding* *folds* |
7 | 8 |
9 You can find an introduction on folding in chapter 28 of the user manual. | |
10 |usr_28.txt| | |
11 | |
12 1. Fold methods |fold-methods| | |
13 2. Fold commands |fold-commands| | |
14 3. Fold options |fold-options| | |
15 4. Behavior of folds |fold-behavior| | |
16 | |
2570
71b56b4e7785
Make the references to features in the help more consistent. (Sylvain Hitier)
Bram Moolenaar <bram@vim.org>
parents:
2561
diff
changeset
|
17 {not available when compiled without the |+folding| feature} |
7 | 18 |
19 ============================================================================== | |
20 1. Fold methods *fold-methods* | |
21 | |
22 The folding method can be set with the 'foldmethod' option. | |
23 | |
24 When setting 'foldmethod' to a value other than "manual", all folds are | |
25 deleted and new ones created. Switching to the "manual" method doesn't remove | |
26 the existing folds. This can be used to first define the folds automatically | |
27 and then change them manually. | |
28 | |
29 There are six methods to select folds: | |
30 manual manually define folds | |
31 indent more indent means a higher fold level | |
32 expr specify an expression to define folds | |
33 syntax folds defined by syntax highlighting | |
34 diff folds for unchanged text | |
35 marker folds defined by markers in the text | |
36 | |
37 | |
38 MANUAL *fold-manual* | |
39 | |
40 Use commands to manually define the fold regions. This can also be used by a | |
41 script that parses text to find folds. | |
42 | |
43 The level of a fold is only defined by its nesting. To increase the fold | |
44 level of a fold for a range of lines, define a fold inside it that has the | |
45 same lines. | |
46 | |
47 The manual folds are lost when you abandon the file. To save the folds use | |
48 the |:mkview| command. The view can be restored later with |:loadview|. | |
49 | |
50 | |
51 INDENT *fold-indent* | |
52 | |
53 The folds are automatically defined by the indent of the lines. | |
54 | |
55 The foldlevel is computed from the indent of the line, divided by the | |
56 'shiftwidth' (rounded down). A sequence of lines with the same or higher fold | |
57 level form a fold, with the lines with a higher level forming a nested fold. | |
58 | |
59 The nesting of folds is limited with 'foldnestmax'. | |
60 | |
61 Some lines are ignored and get the fold level of the line above or below it, | |
2826 | 62 whichever is lower. These are empty or white lines and lines starting |
7 | 63 with a character in 'foldignore'. White space is skipped before checking for |
64 characters in 'foldignore'. For C use "#" to ignore preprocessor lines. | |
65 | |
11062 | 66 When you want to ignore lines in another way, use the "expr" method. The |
7 | 67 |indent()| function can be used in 'foldexpr' to get the indent of a line. |
68 | |
69 | |
70 EXPR *fold-expr* | |
71 | |
72 The folds are automatically defined by their foldlevel, like with the "indent" | |
73 method. The value of the 'foldexpr' option is evaluated to get the foldlevel | |
74 of a line. Examples: | |
1255 | 75 This will create a fold for all consecutive lines that start with a tab: > |
7 | 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 This will make a fold out of paragraphs separated by blank lines: > | |
80 :set foldexpr=getline(v:lnum)=~'^\\s*$'&&getline(v:lnum+1)=~'\\S'?'<1':1 | |
11229
146a1e213b60
Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents:
11062
diff
changeset
|
81 This does the same: > |
7 | 82 :set foldexpr=getline(v:lnum-1)=~'^\\s*$'&&getline(v:lnum)=~'\\S'?'>1':1 |
83 | |
84 Note that backslashes must be used to escape characters that ":set" handles | |
85 differently (space, backslash, double quote, etc., see |option-backslash|). | |
86 | |
87 These are the conditions with which the expression is evaluated: | |
88 - The current buffer and window are set for the line. | |
89 - The variable "v:lnum" is set to the line number. | |
90 - The result is used for the fold level in this way: | |
91 value meaning ~ | |
92 0 the line is not in a fold | |
93 1, 2, .. the line is in a fold with this level | |
94 -1 the fold level is undefined, use the fold level of a | |
95 line before or after this line, whichever is the | |
96 lowest. | |
97 "=" use fold level from the previous line | |
98 "a1", "a2", .. add one, two, .. to the fold level of the previous | |
7272
17333ebd2bbd
commit https://github.com/vim/vim/commit/d042dc825c9b97dacd84d4728f88300da4d5b6b9
Christian Brabandt <cb@256bit.org>
parents:
6725
diff
changeset
|
99 line, use the result for the current line |
7 | 100 "s1", "s2", .. subtract one, two, .. from the fold level of the |
7272
17333ebd2bbd
commit https://github.com/vim/vim/commit/d042dc825c9b97dacd84d4728f88300da4d5b6b9
Christian Brabandt <cb@256bit.org>
parents:
6725
diff
changeset
|
101 previous line, use the result for the next line |
7 | 102 "<1", "<2", .. a fold with this level ends at this line |
103 ">1", ">2", .. a fold with this level starts at this line | |
104 | |
105 It is not required to mark the start (end) of a fold with ">1" ("<1"), a fold | |
106 will also start (end) when the fold level is higher (lower) than the fold | |
107 level of the previous line. | |
108 | |
109 There must be no side effects from the expression. The text in the buffer, | |
110 cursor position, the search patterns, options etc. must not be changed. | |
818 | 111 You can change and restore them if you are careful. |
7 | 112 |
113 If there is some error in the expression, or the resulting value isn't | |
114 recognized, there is no error message and the fold level will be zero. | |
115 For debugging the 'debug' option can be set to "msg", the error messages will | |
116 be visible then. | |
117 | |
118 Note: Since the expression has to be evaluated for every line, this fold | |
119 method can be very slow! | |
120 | |
121 Try to avoid the "=", "a" and "s" return values, since Vim often has to search | |
122 backwards for a line for which the fold level is defined. This can be slow. | |
123 | |
26743
c2c40cefc17b
patch 8.2.3900: it is not easy to use a script-local function for an option
Bram Moolenaar <Bram@vim.org>
parents:
25402
diff
changeset
|
124 If the 'foldexpr' expression starts with s: or |<SID>|, then it is replaced |
26759
31c23760d590
patch 8.2.3908: cannot use a script-local function for 'foldtext'
Bram Moolenaar <Bram@vim.org>
parents:
26743
diff
changeset
|
125 with the script ID (|local-function|). Examples: > |
26743
c2c40cefc17b
patch 8.2.3900: it is not easy to use a script-local function for an option
Bram Moolenaar <Bram@vim.org>
parents:
25402
diff
changeset
|
126 set foldexpr=s:MyFoldExpr() |
c2c40cefc17b
patch 8.2.3900: it is not easy to use a script-local function for an option
Bram Moolenaar <Bram@vim.org>
parents:
25402
diff
changeset
|
127 set foldexpr=<SID>SomeFoldExpr() |
c2c40cefc17b
patch 8.2.3900: it is not easy to use a script-local function for an option
Bram Moolenaar <Bram@vim.org>
parents:
25402
diff
changeset
|
128 < |
7272
17333ebd2bbd
commit https://github.com/vim/vim/commit/d042dc825c9b97dacd84d4728f88300da4d5b6b9
Christian Brabandt <cb@256bit.org>
parents:
6725
diff
changeset
|
129 An example of using "a1" and "s1": For a multi-line C comment, a line |
17333ebd2bbd
commit https://github.com/vim/vim/commit/d042dc825c9b97dacd84d4728f88300da4d5b6b9
Christian Brabandt <cb@256bit.org>
parents:
6725
diff
changeset
|
130 containing "/*" would return "a1" to start a fold, and a line containing "*/" |
17333ebd2bbd
commit https://github.com/vim/vim/commit/d042dc825c9b97dacd84d4728f88300da4d5b6b9
Christian Brabandt <cb@256bit.org>
parents:
6725
diff
changeset
|
131 would return "s1" to end the fold after that line: > |
17333ebd2bbd
commit https://github.com/vim/vim/commit/d042dc825c9b97dacd84d4728f88300da4d5b6b9
Christian Brabandt <cb@256bit.org>
parents:
6725
diff
changeset
|
132 if match(thisline, '/\*') >= 0 |
17333ebd2bbd
commit https://github.com/vim/vim/commit/d042dc825c9b97dacd84d4728f88300da4d5b6b9
Christian Brabandt <cb@256bit.org>
parents:
6725
diff
changeset
|
133 return 'a1' |
17333ebd2bbd
commit https://github.com/vim/vim/commit/d042dc825c9b97dacd84d4728f88300da4d5b6b9
Christian Brabandt <cb@256bit.org>
parents:
6725
diff
changeset
|
134 elseif match(thisline, '\*/') >= 0 |
17333ebd2bbd
commit https://github.com/vim/vim/commit/d042dc825c9b97dacd84d4728f88300da4d5b6b9
Christian Brabandt <cb@256bit.org>
parents:
6725
diff
changeset
|
135 return 's1' |
17333ebd2bbd
commit https://github.com/vim/vim/commit/d042dc825c9b97dacd84d4728f88300da4d5b6b9
Christian Brabandt <cb@256bit.org>
parents:
6725
diff
changeset
|
136 else |
17333ebd2bbd
commit https://github.com/vim/vim/commit/d042dc825c9b97dacd84d4728f88300da4d5b6b9
Christian Brabandt <cb@256bit.org>
parents:
6725
diff
changeset
|
137 return '=' |
17333ebd2bbd
commit https://github.com/vim/vim/commit/d042dc825c9b97dacd84d4728f88300da4d5b6b9
Christian Brabandt <cb@256bit.org>
parents:
6725
diff
changeset
|
138 endif |
17333ebd2bbd
commit https://github.com/vim/vim/commit/d042dc825c9b97dacd84d4728f88300da4d5b6b9
Christian Brabandt <cb@256bit.org>
parents:
6725
diff
changeset
|
139 However, this won't work for single line comments, strings, etc. |
17333ebd2bbd
commit https://github.com/vim/vim/commit/d042dc825c9b97dacd84d4728f88300da4d5b6b9
Christian Brabandt <cb@256bit.org>
parents:
6725
diff
changeset
|
140 |
7 | 141 |foldlevel()| can be useful to compute a fold level relative to a previous |
142 fold level. But note that foldlevel() may return -1 if the level is not known | |
143 yet. And it returns the level at the start of the line, while a fold might | |
144 end in that line. | |
145 | |
11062 | 146 It may happen that folds are not updated properly. You can use |zx| or |zX| |
2152 | 147 to force updating folds. |
148 | |
7 | 149 |
150 SYNTAX *fold-syntax* | |
151 | |
152 A fold is defined by syntax items that have the "fold" argument. |:syn-fold| | |
153 | |
154 The fold level is defined by nesting folds. The nesting of folds is limited | |
155 with 'foldnestmax'. | |
156 | |
157 Be careful to specify proper syntax syncing. If this is not done right, folds | |
158 may differ from the displayed highlighting. This is especially relevant when | |
159 using patterns that match more than one line. In case of doubt, try using | |
160 brute-force syncing: > | |
161 :syn sync fromstart | |
162 | |
163 | |
164 DIFF *fold-diff* | |
165 | |
166 The folds are automatically defined for text that is not part of a change or | |
167 close to a change. | |
168 | |
169 This method only works properly when the 'diff' option is set for the current | |
170 window and changes are being displayed. Otherwise the whole buffer will be | |
171 one big fold. | |
172 | |
173 The 'diffopt' option can be used to specify the context. That is, the number | |
174 of lines between the fold and a change that are not included in the fold. For | |
175 example, to use a context of 8 lines: > | |
176 :set diffopt=filler,context:8 | |
177 The default context is six lines. | |
178 | |
179 When 'scrollbind' is also set, Vim will attempt to keep the same folds open in | |
180 other diff windows, so that the same text is visible. | |
181 | |
182 | |
183 MARKER *fold-marker* | |
184 | |
185 Markers in the text tell where folds start and end. This allows you to | |
186 precisely specify the folds. This will allow deleting and putting a fold, | |
187 without the risk of including the wrong lines. The 'foldtext' option is | |
188 normally set such that the text before the marker shows up in the folded line. | |
189 This makes it possible to give a name to the fold. | |
190 | |
191 Markers can have a level included, or can use matching pairs. Including a | |
192 level is easier, you don't have to add end markers and avoid problems with | |
193 non-matching marker pairs. Example: > | |
194 /* global variables {{{1 */ | |
195 int varA, varB; | |
196 | |
197 /* functions {{{1 */ | |
198 /* funcA() {{{2 */ | |
199 void funcA() {} | |
200 | |
201 /* funcB() {{{2 */ | |
202 void funcB() {} | |
203 | |
204 A fold starts at a "{{{" marker. The following number specifies the fold | |
205 level. What happens depends on the difference between the current fold level | |
206 and the level given by the marker: | |
207 1. If a marker with the same fold level is encountered, the previous fold | |
208 ends and another fold with the same level starts. | |
209 2. If a marker with a higher fold level is found, a nested fold is started. | |
11229
146a1e213b60
Update runtime files. Add Rust support.
Christian Brabandt <cb@256bit.org>
parents:
11062
diff
changeset
|
210 3. If a marker with a lower fold level is found, all folds up to and including |
7 | 211 this level end and a fold with the specified level starts. |
212 | |
33 | 213 The number indicates the fold level. A zero cannot be used (a marker with |
214 level zero is ignored). You can use "}}}" with a digit to indicate the level | |
215 of the fold that ends. The fold level of the following line will be one less | |
216 than the indicated level. Note that Vim doesn't look back to the level of the | |
217 matching marker (that would take too much time). Example: > | |
7 | 218 |
219 {{{1 | |
220 fold level here is 1 | |
221 {{{3 | |
222 fold level here is 3 | |
223 }}}3 | |
224 fold level here is 2 | |
225 | |
226 You can also use matching pairs of "{{{" and "}}}" markers to define folds. | |
227 Each "{{{" increases the fold level by one, each "}}}" decreases the fold | |
228 level by one. Be careful to keep the markers matching! Example: > | |
229 | |
230 {{{ | |
231 fold level here is 1 | |
232 {{{ | |
233 fold level here is 2 | |
234 }}} | |
235 fold level here is 1 | |
236 | |
237 You can mix using markers with a number and without a number. A useful way of | |
238 doing this is to use numbered markers for large folds, and unnumbered markers | |
239 locally in a function. For example use level one folds for the sections of | |
240 your file like "structure definitions", "local variables" and "functions". | |
241 Use level 2 markers for each definition and function, Use unnumbered markers | |
242 inside functions. When you make changes in a function to split up folds, you | |
243 don't have to renumber the markers. | |
244 | |
245 The markers can be set with the 'foldmarker' option. It is recommended to | |
246 keep this at the default value of "{{{,}}}", so that files can be exchanged | |
247 between Vim users. Only change it when it is required for the file (e.g., it | |
248 contains markers from another folding editor, or the default markers cause | |
249 trouble for the language of the file). | |
250 | |
251 *fold-create-marker* | |
252 "zf" can be used to create a fold defined by markers. Vim will insert the | |
253 markers for you. Vim will append the start and end marker, as specified with | |
254 'foldmarker'. The markers are appended to the end of the line. | |
255 'commentstring' is used if it isn't empty. | |
256 This does not work properly when: | |
257 - The line already contains a marker with a level number. Vim then doesn't | |
258 know what to do. | |
259 - Folds nearby use a level number in their marker which gets in the way. | |
260 - The line is inside a comment, 'commentstring' isn't empty and nested | |
261 comments don't work. For example with C: adding /* {{{ */ inside a comment | |
262 will truncate the existing comment. Either put the marker before or after | |
263 the comment, or add the marker manually. | |
264 Generally it's not a good idea to let Vim create markers when you already have | |
265 markers with a level number. | |
266 | |
267 *fold-delete-marker* | |
268 "zd" can be used to delete a fold defined by markers. Vim will delete the | |
269 markers for you. Vim will search for the start and end markers, as specified | |
270 with 'foldmarker', at the start and end of the fold. When the text around the | |
271 marker matches with 'commentstring', that text is deleted as well. | |
272 This does not work properly when: | |
273 - A line contains more than one marker and one of them specifies a level. | |
274 Only the first one is removed, without checking if this will have the | |
275 desired effect of deleting the fold. | |
276 - The marker contains a level number and is used to start or end several folds | |
277 at the same time. | |
278 | |
279 ============================================================================== | |
280 2. Fold commands *fold-commands* *E490* | |
281 | |
282 All folding commands start with "z". Hint: the "z" looks like a folded piece | |
283 of paper, if you look at it from the side. | |
284 | |
285 | |
286 CREATING AND DELETING FOLDS ~ | |
287 *zf* *E350* | |
288 zf{motion} or | |
289 {Visual}zf Operator to create a fold. | |
290 This only works when 'foldmethod' is "manual" or "marker". | |
291 The new fold will be closed for the "manual" method. | |
292 'foldenable' will be set. | |
293 Also see |fold-create-marker|. | |
294 | |
295 *zF* | |
2098
3259c3923c1e
Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
2033
diff
changeset
|
296 zF Create a fold for [count] lines. Works like "zf". |
7 | 297 |
298 :{range}fo[ld] *:fold* *:fo* | |
299 Create a fold for the lines in {range}. Works like "zf". | |
300 | |
301 *zd* *E351* | |
42 | 302 zd Delete one fold at the cursor. When the cursor is on a folded |
7 | 303 line, that fold is deleted. Nested folds are moved one level |
5555 | 304 up. In Visual mode one level of all folds (partially) in the |
305 selected area are deleted. | |
306 Careful: This easily deletes more folds than you expect and | |
307 there is no undo for manual folding. | |
7 | 308 This only works when 'foldmethod' is "manual" or "marker". |
309 Also see |fold-delete-marker|. | |
310 | |
311 *zD* | |
312 zD Delete folds recursively at the cursor. In Visual mode all | |
313 folds (partially) in the selected area and all nested folds in | |
314 them are deleted. | |
315 This only works when 'foldmethod' is "manual" or "marker". | |
316 Also see |fold-delete-marker|. | |
317 | |
318 *zE* *E352* | |
319 zE Eliminate all folds in the window. | |
320 This only works when 'foldmethod' is "manual" or "marker". | |
321 Also see |fold-delete-marker|. | |
322 | |
323 | |
324 OPENING AND CLOSING FOLDS ~ | |
325 | |
326 A fold smaller than 'foldminlines' will always be displayed like it was open. | |
327 Therefore the commands below may work differently on small folds. | |
328 | |
329 *zo* | |
330 zo Open one fold under the cursor. When a count is given, that | |
331 many folds deep will be opened. In Visual mode one level of | |
332 folds is opened for all lines in the selected area. | |
333 | |
334 *zO* | |
335 zO Open all folds under the cursor recursively. Folds that don't | |
336 contain the cursor line are unchanged. | |
337 In Visual mode it opens all folds that are in the selected | |
338 area, also those that are only partly selected. | |
339 | |
340 *zc* | |
341 zc Close one fold under the cursor. When a count is given, that | |
342 many folds deep are closed. In Visual mode one level of folds | |
343 is closed for all lines in the selected area. | |
344 'foldenable' will be set. | |
345 | |
346 *zC* | |
347 zC Close all folds under the cursor recursively. Folds that | |
348 don't contain the cursor line are unchanged. | |
349 In Visual mode it closes all folds that are in the selected | |
350 area, also those that are only partly selected. | |
351 'foldenable' will be set. | |
352 | |
353 *za* | |
236 | 354 za When on a closed fold: open it. When folds are nested, you |
7 | 355 may have to use "za" several times. When a count is given, |
356 that many closed folds are opened. | |
357 When on an open fold: close it and set 'foldenable'. This | |
358 will only close one level, since using "za" again will open | |
359 the fold. When a count is given that many folds will be | |
360 closed (that's not the same as repeating "za" that many | |
361 times). | |
362 | |
363 *zA* | |
364 zA When on a closed fold: open it recursively. | |
365 When on an open fold: close it recursively and set | |
366 'foldenable'. | |
367 | |
368 *zv* | |
369 zv View cursor line: Open just enough folds to make the line in | |
370 which the cursor is located not folded. | |
371 | |
372 *zx* | |
373 zx Update folds: Undo manually opened and closed folds: re-apply | |
374 'foldlevel', then do "zv": View cursor line. | |
2152 | 375 Also forces recomputing folds. This is useful when using |
376 'foldexpr' and the buffer is changed in a way that results in | |
377 folds not to be updated properly. | |
7 | 378 |
379 *zX* | |
380 zX Undo manually opened and closed folds: re-apply 'foldlevel'. | |
2152 | 381 Also forces recomputing folds, like |zx|. |
7 | 382 |
383 *zm* | |
6725 | 384 zm Fold more: Subtract |v:count1| from 'foldlevel'. If 'foldlevel' was |
7 | 385 already zero nothing happens. |
386 'foldenable' will be set. | |
387 | |
388 *zM* | |
389 zM Close all folds: set 'foldlevel' to 0. | |
390 'foldenable' will be set. | |
391 | |
392 *zr* | |
6725 | 393 zr Reduce folding: Add |v:count1| to 'foldlevel'. |
7 | 394 |
395 *zR* | |
396 zR Open all folds. This sets 'foldlevel' to highest fold level. | |
397 | |
398 *:foldo* *:foldopen* | |
399 :{range}foldo[pen][!] | |
400 Open folds in {range}. When [!] is added all folds are | |
401 opened. Useful to see all the text in {range}. Without [!] | |
402 one level of folds is opened. | |
403 | |
404 *:foldc* *:foldclose* | |
405 :{range}foldc[lose][!] | |
406 Close folds in {range}. When [!] is added all folds are | |
407 closed. Useful to hide all the text in {range}. Without [!] | |
408 one level of folds is closed. | |
409 | |
410 *zn* | |
411 zn Fold none: reset 'foldenable'. All folds will be open. | |
412 | |
413 *zN* | |
414 zN Fold normal: set 'foldenable'. All folds will be as they | |
415 were before. | |
416 | |
417 *zi* | |
418 zi Invert 'foldenable'. | |
419 | |
420 | |
421 MOVING OVER FOLDS ~ | |
422 *[z* | |
423 [z Move to the start of the current open fold. If already at the | |
424 start, move to the start of the fold that contains it. If | |
425 there is no containing fold, the command fails. | |
2098
3259c3923c1e
Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
2033
diff
changeset
|
426 When a count is used, repeats the command [count] times. |
7 | 427 |
428 *]z* | |
429 ]z Move to the end of the current open fold. If already at the | |
430 end, move to the end of the fold that contains it. If there | |
431 is no containing fold, the command fails. | |
2098
3259c3923c1e
Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
2033
diff
changeset
|
432 When a count is used, repeats the command [count] times. |
7 | 433 |
434 *zj* | |
435 zj Move downwards to the start of the next fold. A closed fold | |
436 is counted as one fold. | |
2098
3259c3923c1e
Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
2033
diff
changeset
|
437 When a count is used, repeats the command [count] times. |
7 | 438 This command can be used after an |operator|. |
439 | |
440 *zk* | |
441 zk Move upwards to the end of the previous fold. A closed fold | |
442 is counted as one fold. | |
2098
3259c3923c1e
Updated runtime an documentation files.
Bram Moolenaar <bram@zimbu.org>
parents:
2033
diff
changeset
|
443 When a count is used, repeats the command [count] times. |
7 | 444 This command can be used after an |operator|. |
445 | |
446 | |
447 EXECUTING COMMANDS ON FOLDS ~ | |
448 | |
16944 | 449 :[range]foldd[oopen] {cmd} *:foldd* *:folddo* *:folddoopen* |
7 | 450 Execute {cmd} on all lines that are not in a closed fold. |
451 When [range] is given, only these lines are used. | |
452 Each time {cmd} is executed the cursor is positioned on the | |
453 line it is executed for. | |
454 This works like the ":global" command: First all lines that | |
455 are not in a closed fold are marked. Then the {cmd} is | |
456 executed for all marked lines. Thus when {cmd} changes the | |
457 folds, this has no influence on where it is executed (except | |
458 when lines are deleted, of course). | |
459 Example: > | |
460 :folddoopen s/end/loop_end/ge | |
461 < Note the use of the "e" flag to avoid getting an error message | |
462 where "end" doesn't match. | |
463 | |
464 :[range]folddoc[losed] {cmd} *:folddoc* *:folddoclosed* | |
465 Execute {cmd} on all lines that are in a closed fold. | |
466 Otherwise like ":folddoopen". | |
467 | |
468 ============================================================================== | |
469 3. Fold options *fold-options* | |
470 | |
471 COLORS *fold-colors* | |
472 | |
473 The colors of a closed fold are set with the Folded group |hl-Folded|. The | |
474 colors of the fold column are set with the FoldColumn group |hl-FoldColumn|. | |
475 Example to set the colors: > | |
476 | |
477 :highlight Folded guibg=grey guifg=blue | |
478 :highlight FoldColumn guibg=darkgrey guifg=white | |
479 | |
480 | |
481 FOLDLEVEL *fold-foldlevel* | |
482 | |
483 'foldlevel' is a number option: The higher the more folded regions are open. | |
484 When 'foldlevel' is 0, all folds are closed. | |
42 | 485 When 'foldlevel' is positive, some folds are closed. |
7 | 486 When 'foldlevel' is very high, all folds are open. |
487 'foldlevel' is applied when it is changed. After that manually folds can be | |
488 opened and closed. | |
489 When increased, folds above the new level are opened. No manually opened | |
490 folds will be closed. | |
491 When decreased, folds above the new level are closed. No manually closed | |
492 folds will be opened. | |
493 | |
494 | |
495 FOLDTEXT *fold-foldtext* | |
496 | |
497 'foldtext' is a string option that specifies an expression. This expression | |
498 is evaluated to obtain the text displayed for a closed fold. Example: > | |
499 | |
500 :set foldtext=v:folddashes.substitute(getline(v:foldstart),'/\\*\\\|\\*/\\\|{{{\\d\\=','','g') | |
501 | |
502 This shows the first line of the fold, with "/*", "*/" and "{{{" removed. | |
503 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: > | |
505 | |
506 :set foldtext=MyFoldText() | |
507 :function MyFoldText() | |
508 : let line = getline(v:foldstart) | |
509 : let sub = substitute(line, '/\*\|\*/\|{{{\d\=', '', 'g') | |
27903 | 510 : return v:folddashes .. sub |
7 | 511 :endfunction |
512 | |
513 Evaluating 'foldtext' is done in the |sandbox|. The current window is set to | |
27321 | 514 the window that displays the line. The context is set to the script where the |
515 option was last set. | |
516 | |
517 Errors are ignored. For debugging set the 'debug' option to "throw". | |
7 | 518 |
519 The default value is |foldtext()|. This returns a reasonable text for most | |
520 types of folding. If you don't like it, you can specify your own 'foldtext' | |
521 expression. It can use these special Vim variables: | |
522 v:foldstart line number of first line in the fold | |
523 v:foldend line number of last line in the fold | |
524 v:folddashes a string that contains dashes to represent the | |
525 foldlevel. | |
526 v:foldlevel the foldlevel of the fold | |
527 | |
528 In the result a TAB is replaced with a space and unprintable characters are | |
529 made into printable characters. | |
530 | |
531 The resulting line is truncated to fit in the window, it never wraps. | |
532 When there is room after the text, it is filled with the character specified | |
533 by 'fillchars'. | |
534 | |
26759
31c23760d590
patch 8.2.3908: cannot use a script-local function for 'foldtext'
Bram Moolenaar <Bram@vim.org>
parents:
26743
diff
changeset
|
535 If the 'foldtext' expression starts with s: or |<SID>|, then it is replaced |
31c23760d590
patch 8.2.3908: cannot use a script-local function for 'foldtext'
Bram Moolenaar <Bram@vim.org>
parents:
26743
diff
changeset
|
536 with the script ID (|local-function|). Examples: > |
31c23760d590
patch 8.2.3908: cannot use a script-local function for 'foldtext'
Bram Moolenaar <Bram@vim.org>
parents:
26743
diff
changeset
|
537 set foldtext=s:MyFoldText() |
31c23760d590
patch 8.2.3908: cannot use a script-local function for 'foldtext'
Bram Moolenaar <Bram@vim.org>
parents:
26743
diff
changeset
|
538 set foldtext=<SID>SomeFoldText() |
31c23760d590
patch 8.2.3908: cannot use a script-local function for 'foldtext'
Bram Moolenaar <Bram@vim.org>
parents:
26743
diff
changeset
|
539 < |
7 | 540 Note that backslashes need to be used for characters that the ":set" command |
541 handles differently: Space, backslash and double-quote. |option-backslash| | |
542 | |
543 | |
544 FOLDCOLUMN *fold-foldcolumn* | |
545 | |
546 'foldcolumn' is a number, which sets the width for a column on the side of the | |
547 window to indicate folds. When it is zero, there is no foldcolumn. A normal | |
519 | 548 value is 4 or 5. The minimal useful value is 2, although 1 still provides |
549 some information. The maximum is 12. | |
7 | 550 |
551 An open fold is indicated with a column that has a '-' at the top and '|' | |
552 characters below it. This column stops where the open fold stops. When folds | |
553 nest, the nested fold is one character right of the fold it's contained in. | |
554 | |
555 A closed fold is indicated with a '+'. | |
556 | |
25402 | 557 These characters can be changed with the 'fillchars' option. |
558 | |
7 | 559 Where the fold column is too narrow to display all nested folds, digits are |
560 shown to indicate the nesting level. | |
561 | |
562 The mouse can also be used to open and close folds by clicking in the | |
563 fold column: | |
564 - Click on a '+' to open the closed fold at this row. | |
565 - Click on any other non-blank character to close the open fold at this row. | |
566 | |
567 | |
568 OTHER OPTIONS | |
569 | |
570 'foldenable' 'fen': Open all folds while not set. | |
571 'foldexpr' 'fde': Expression used for "expr" folding. | |
572 'foldignore' 'fdi': Characters used for "indent" folding. | |
573 'foldmarker' 'fmr': Defined markers used for "marker" folding. | |
574 'foldmethod' 'fdm': Name of the current folding method. | |
575 'foldminlines' 'fml': Minimum number of screen lines for a fold to be | |
576 displayed closed. | |
577 'foldnestmax' 'fdn': Maximum nesting for "indent" and "syntax" folding. | |
578 'foldopen' 'fdo': Which kinds of commands open closed folds. | |
579 'foldclose' 'fcl': When the folds not under the cursor are closed. | |
580 | |
581 ============================================================================== | |
582 4. Behavior of folds *fold-behavior* | |
583 | |
584 When moving the cursor upwards or downwards and when scrolling, the cursor | |
585 will move to the first line of a sequence of folded lines. When the cursor is | |
586 already on a folded line, it moves to the next unfolded line or the next | |
587 closed fold. | |
588 | |
589 While the cursor is on folded lines, the cursor is always displayed in the | |
590 first column. The ruler does show the actual cursor position, but since the | |
591 line is folded, it cannot be displayed there. | |
592 | |
593 Many movement commands handle a sequence of folded lines like an empty line. | |
594 For example, the "w" command stops once in the first column. | |
595 | |
596 When in Insert mode, the cursor line is never folded. That allows you to see | |
597 what you type! | |
598 | |
599 When using an operator, a closed fold is included as a whole. Thus "dl" | |
600 deletes the whole closed fold under the cursor. | |
601 | |
7465
71e2aca45b81
commit https://github.com/vim/vim/commit/a3306958dcb9aadff1e1e8521d908d86b10ac99a
Christian Brabandt <cb@256bit.org>
parents:
7272
diff
changeset
|
602 For Ex commands that work on buffer lines the range is adjusted to always |
71e2aca45b81
commit https://github.com/vim/vim/commit/a3306958dcb9aadff1e1e8521d908d86b10ac99a
Christian Brabandt <cb@256bit.org>
parents:
7272
diff
changeset
|
603 start at the first line of a closed fold and end at the last line of a closed |
71e2aca45b81
commit https://github.com/vim/vim/commit/a3306958dcb9aadff1e1e8521d908d86b10ac99a
Christian Brabandt <cb@256bit.org>
parents:
7272
diff
changeset
|
604 fold. Thus this command: > |
7 | 605 :s/foo/bar/g |
606 when used with the cursor on a closed fold, will replace "foo" with "bar" in | |
607 all lines of the fold. | |
608 This does not happen for |:folddoopen| and |:folddoclosed|. | |
609 | |
610 When editing a buffer that has been edited before, the last used folding | |
611 settings are used again. For manual folding the defined folds are restored. | |
612 For all folding methods the manually opened and closed folds are restored. | |
613 If this buffer has been edited in this window, the values from back then are | |
614 used. Otherwise the values from the window where the buffer was edited last | |
615 are used. | |
616 | |
617 ============================================================================== | |
14421 | 618 vim:tw=78:ts=8:noet:ft=help:norl: |