Skip to content
Go to file

Latest commit


Git stats


Failed to load latest commit information.

What good will FastFold do?

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 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).

Example Setup

Each of these triggers for updating folds can be modified or disabled by adding the lines

nmap zuz <Plug>(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 file ~/.vimrc (respectively %USERPROFILE%/_vimrc on Microsoft Windows).

For example, by adding

let g:markdown_folding = 1
let g:tex_fold_enabled = 1
let g:vimsyn_folding = 'af'
let g:xml_syntax_folding = 1
let g:javaScript_fold = 1
let g:sh_fold_enabled= 7
let g:ruby_fold = 1
let g:perl_fold = 1
let g:perl_fold_blocks = 1
let g:r_syntax_folding = 1
let g:rust_fold = 1
let g:php_folding = 1

to the .vimrc file and installing this plug-in, the folds in a TeX, Vim, XML, JavaScript, R, 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. (Likewise, in a Markdown or Rust file, by the expression fold method.)


  • 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 not updated whenever you close or open folds by a standard keystroke such as zx,zo or zc, then add let 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 variable g:fastfold_mapsuffixes. If you wanted to intercept all possible fold commands (such as zr,zm,...), change this to:

    let g:fastfold_fold_command_suffixes =
  • If you prefer that this plug-in does not add a normal mode mapping that updates folds (that defaults to zuz), then add nmap <SID>(DisableFastFoldUpdate) <Plug>(FastFoldUpdate) to your .vimrc.

    You can remap zuz to your favorite keystroke, say <F5>, by adding nmap <F5> <Plug>(FastFoldUpdate) to your .vimrc.

    There is also a command FastFoldUpdate that updates all folds and its variant FastFoldUpdate! that updates all folds and echos by which fold method the folds were updated.

  • FastFold by default only prevents the expression and syntax fold methods from recomputing on every buffer change. To prevent all fold methods (except manual) from doing so, add let g:fastfold_force = 1 to your .vimrc.

  • FastFold is by default enabled for files that have more than a certain number of lines, by default set to 200. To change this number, for example, to enable FastFold independent of the number of lines of a file, add let g:fastfold_minlines = 0 to your .vimrc.


FastFold overwrites your manual folds when saving the currently edited buffer, unless

  • FastFold is disabled for this filetype by g:fastfold_skip_filetypes, or
  • the foldmethod=manual since having entered the buffer.

To ensure that sessions do not override the default fold method of the buffer file type (by the value manual), set sessionoptions-=folds in your vimrc. For a thorougher solution, install vim-stay discussed below.



FastFold integrates with the plug-in vim-stay that restores the folds of a file buffer by :mkview and :loadview.

Custom Fold Text

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, similar to that by Greg Sexton, is available at


FastFold integrates with the plug-in NrrwRgn that lets you edit a selection in a new temporary buffer by adding to your vimrc the line

  autocmd BufWinEnter * let b:nrrw_aucmd_create = "let w:lastfdm = getwinvar(winnr('#'), 'lastfdm')"

Fold Text-Object

Create a fold text object, mapped to iz and az, by adding the lines

xnoremap iz :<c-u>FastFoldUpdate<cr><esc>:<c-u>normal! ]zv[z<cr>
xnoremap az :<c-u>FastFoldUpdate<cr><esc>:<c-u>normal! ]zV[z<cr>

to the file ~/.vimrc (respectively %USERPROFILE%/_vimrc on Microsoft Windows).


Speed up Vim by updating folds only when called-for.



No packages published
You can’t perform that action at this time.