Edit Page
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 38: | Line 38: | ||
===Indent folding=== |
===Indent folding=== |
||
+ | In the vimrc, set the foldcolumn and foldlevel to the depth of folds you want displayed. A sidebar will appear showing which lines in the file can be folded, or are already folded. |
||
− | As noted above, with 'foldmethod' set to indent, lines with the same level of indentation will be folded together. Note this means text like this: |
||
− | |||
− | <pre> |
||
− | Line one |
||
− | Line two |
||
− | Line three |
||
− | Line four |
||
− | </pre> |
||
− | |||
− | will be folded as follows, which may not be expected: |
||
− | |||
− | <pre> |
||
− | Line one |
||
− | + Line two and three |
||
− | Line four |
||
− | </pre> |
||
− | |||
− | Since folding by indent may not be as clear as you like, the foldcolumn is especially useful for this method. Setting foldcolumn to at least the level of folds you want displayed will show a sidebar, in which you can see which lines in the file can be folded, or are already folded, with a '+' (closed) or '-' (open) indicator. |
||
===Syntax folding=== |
===Syntax folding=== |
||
Line 77: | Line 60: | ||
===Folding with markers=== |
===Folding with markers=== |
||
− | Setting foldmethod to "marker" is similar to manual folding, because you can use zf and zd to add/remove folds, and all folds are defined manually. However, it works by adding special markers to your buffer text so that the same folds can be loaded by anyone opening the file in Vim |
+ | Setting foldmethod to "marker" is similar to manual folding, because you can use zf and zd to add/remove folds, and all folds are defined manually. However, it works by adding special markers to your buffer text so that the same folds can be loaded by anyone opening the file in Vim. This method is mostly useful when the other options don't give satisfactory results, either because a syntax file does not define folding, you want to break up a file into logical portions instead of syntactical constructs, or you are folding plain text in some way. |
− | |||
− | If you change the default 'foldmarker' setting, be sure to communicate the correct setting to other people in some way. An especially effective method for this would be to use a [[Modeline magic|modeline]], so that most Vim users will get your intended settings by default when they edit the file. |
||
===Diff folding=== |
===Diff folding=== |
||
Line 112: | Line 93: | ||
In the first mapping for Space, <code>@=</code> refers to the expression register ({{help|1=@=}}). The following expression is evaluated when Enter is pressed (<code><CR></code>). The value of <code>foldlevel('.')</code> is determined (the fold level at the current line, or zero if the current line is not in a fold). If the result is nonzero (true), the result is <code>'za'</code> (toggle fold); otherwise it is <code>"\<Space>"</code>, which evaluates back to the default behaviour of the <Space> key (move forward by one character). {{help|expr1}} |
In the first mapping for Space, <code>@=</code> refers to the expression register ({{help|1=@=}}). The following expression is evaluated when Enter is pressed (<code><CR></code>). The value of <code>foldlevel('.')</code> is determined (the fold level at the current line, or zero if the current line is not in a fold). If the result is nonzero (true), the result is <code>'za'</code> (toggle fold); otherwise it is <code>"\<Space>"</code>, which evaluates back to the default behaviour of the <Space> key (move forward by one character). {{help|expr1}} |
||
− | ==Saving folds before closing vim== |
+ | ==Saving folds before closing the vim== |
Vim provides a good mechanism called <code>view</code>. You can use it to save a fold. See [[VimTip991|Make views automatic]]. You may also want to use plugin {{script|id=4021|text=restore_view.vim}}. |
Vim provides a good mechanism called <code>view</code>. You can use it to save a fold. See [[VimTip991|Make views automatic]]. You may also want to use plugin {{script|id=4021|text=restore_view.vim}}. |
||