Automatic folds (that is, folds generated by a fold method different
from manual
), bog down VIM noticeably in insert mode. They are also often
recomputed too early (for example, when inserting an opening fold marker
whose closing counterpart is yet missing to complete the fold.)
See http://vim.wikia.com/wiki/Keep_folds_closed_while_inserting_text for a discussion.
With this plug-in, the folds in the currently edited buffer are updated by an automatic fold method only
- when saving the buffer
- when closing or opening folds (zo, za, zc, etc...)
- when moving or operating fold-wise (zj,zk,[z,]z)
- when typing
zuz
in normal mode
and are kept as is otherwise (by keeping the fold method set to manual
). Each
of these triggers for updating folds can be modified or disabled by adding
- nmap zuz (FastFoldUpdate)
- let g:fastfold_savehook = 1
- let g:fastfold_fold_command_suffixes = ['x','X','a','A','o','O','c','C']
- let g:fastfold_fold_movement_commands = [']z', '[z', 'zj', 'zk']
to the .vimrc
file.
For example, by adding
let g:tex_fold_enabled=1
let g:vimsyn_folding='af'
let g:xml_syntax_folding = 1
let g:php_folding = 1
let g:perl_fold = 1
to the .vimrc
file and installing this plug-in, the folds in a TeX, Vim, XML,
PHP or Perl file are updated by the syntax
fold method when saving the
buffer, opening, closing, moving or operating on folds, or typing zuz
in
normal mode and are kept as is otherwise.
Configuration
-
If you prefer that folds are only updated manually but not when saving the buffer, then add
let g:fastfold_savehook = 0
to your.vimrc
. -
If you prefer that folds are updated whenever you close or open folds by a standard keystroke such as
zx
,zo
orzc
, then addlet g:fastfold_fold_command_suffixes = []
to your.vimrc
.The exact list of these standard keystrokes is
zx,zX,za,zA,zo,zO,zc,zC
and it can be customized by changing the global variableg:fastfold_mapsuffixes
. If you wanted to intercept all possible fold commands (such as zr,zm,...), change this to:let g:fastfold_fold_command_suffixes = ['x','X','a','A','o','O','c','C','r','R','m','M','i','n','N']
-
If you prefer that this plug-in does not add a normal mode mapping that updates folds (that defaults to
zuz
), then addnmap <SID>(DisableFastFoldUpdate) <Plug>(FastFoldUpdate)
to your.vimrc
.You can remap
zuz
to your favorite keystroke, say<F5>
, by addingnmap <F5> <Plug>(FastFoldUpdate)
to your.Vimrc
.There is also a command
FastFoldUpdate
that updates all folds and its variantFastFoldUpdate!
that updates all folds and echos by which fold method the folds were updated.
==
Addons
Related Plug-ins
FastFold
integrates with vim-stay
that stores and restores the last folds
by :mkview
and :loadview
.
CustomFoldText
A CustomFoldText()
function that displays the percentage of the number of buffer lines that the folded text takes up and indents folds according to their nesting level is available at