Home

Awesome

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

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:rst_fold_enabled = 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:zsh_fold_enable = 1
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
let g:fortran_fold=1
let g:clojure_fold = 1
let g:baan_fold=1

to the .vimrc file and installing this plug-in, the folds in a TeX, Vim, XML, JavaScript, (Z)SH, R, PHP, Ruby, Perl, Fortran, Clojure or Baan 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, RST or Rust file, by the expression fold method.) Syntax folding for C and C++ files can be enabled by adding

autocmd FileType c,cpp setlocal foldmethod=syntax

to your vimrc (see :help ft-c-syntax). For Python, adding

autocmd FileType python setlocal foldmethod=indent

to your vimrc mostly suffices, though installing SimplyFold refines folds from successive indent levels to syntax objects such as functions.

Configuration

Caveats

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

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.

Addons

Vim-Stay

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

Custom Fold Text

Replace the standard &foldtext

NrrwRgn

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 <silent> iz :<c-u>FastFoldUpdate<cr>]z<up>$v[z<down>^
xnoremap <silent> az :<c-u>FastFoldUpdate<cr>]zV[z

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