

The markers are defined by the 'foldmarker' option, which defaults to three consecutive open curly braces to start a fold and three consecutive closed curly braces to end a fold. 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.

All vim shortcuts manual#
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. For example, you could fold away text not matching a regular expression. You can use it to fold in pretty much any way you desire. This is the most complicated, but also the most powerful fold method. It's executed after the modeline is read, so it won't change the fold method if the modeline set the fold method to something else like 'marker' or 'syntax'. The second one allows you to manually create folds while editing. The first autocommand sets 'indent' as the fold method before a file is loaded, so that indent-based folds will be defined. If you like the convenience of having Vim define folds automatically by indent level, but would also like to create folds manually, you can get both by putting this in your vimrc:Īu BufReadPre * setlocal foldmethod=indentĪu BufWinEnter * if &fdm = 'indent' | setlocal foldmethod=manual | endif You can change this using the 'foldnestmax' option, by setting it to a value low enough for your liking. Note that this particular fold method especially may define too many folds for your liking. If a specific syntax file doesn't define folding, you can define your own. Many syntax files define folding based on the language syntax, although you may need to enable it by setting syntax file options. 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. Since folding by indent may not be as clear as you like, the foldcolumn is especially useful for this method. Will be folded as follows, which may not be expected: Use zd to delete the fold at the cursor (no text is deleted, just the fold markers) zD is used to recursively delete folds at the cursor.Īs noted above, with 'foldmethod' set to indent, lines with the same level of indentation will be folded together. When foldmethod is set to manual (or marker), a fold can be created in Normal mode by typing zffo, e.g., the current line along with the following three lines (as in the example above) can be folded by running :,+3fo. Normally it is best to use an automatic folding method, but manual folding is simple and can be useful for dealing with small folds. diff – used to fold unchanged text when viewing differences (automatically set in diff mode).marker – special characters can be manually or automatically added to your text to flag the start and end of folds.expr – folds are defined by a user-defined expression.syntax – folds are defined by syntax highlighting.indent – groups of lines with the same indent form a fold.manual – folds must be defined by entering commands (such as zf).It determines what kind of folding applies in the current window. The 'foldmethod' option (abbreviated to 'fdm') is local to each window. To activate folding in your text, you will need to set the 'foldmethod' option.
