• Stars
    star
    699
  • Rank 64,759 (Top 2 %)
  • Language
    Vim Script
  • Created over 10 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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

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

  • 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 =
    ['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 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.

Caveats

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.

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

  • by one that displays the percentage of the number of buffer lines that the folded text takes up and indents folds according to their nesting level, originally by Greg Sexton, or
  • by one that previews the most pertinent initial text of the fold (together with the fold level and number of lines).

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

More Repositories

1

win-bash-xclip-xsel

make xclip and xsel in Git Bash or WSL read and write to the Microsoft Windows clipboard
Shell
60
star
2

vim-alias

versatile Vim command-line aliases
Vim Script
59
star
3

vim-compilers

a collection of compilers for ready use by Vim's built-in compiler feature (see :help :compiler)
Vim Script
41
star
4

vim-CtrlXA

make Ctrl-X and Ctrl-A run through keyword cycles
Vim Script
40
star
5

win-bash-gui-bins

start common GUI applications under Git BASH or WSL just like under Linux
Shell
36
star
6

vim-office

read common binary files, such as PDFs and those of Microsoft Office or LibreOffice, in Vim
Vim Script
31
star
7

vim-sentence-chopper

version-control friendly text formatting
Vim Script
27
star
8

vim-DetectSpellLang

make Vim autodetect the spellcheck language of the opened buffer
Vim Script
22
star
9

FoldText

Fancy fold texts
Vim Script
22
star
10

vim-langtool

A Vim plug-in to list and jump to grammar errors found by LanguageTool
Vim Script
19
star
11

vim-scratchpad

toggle a scratchpad in Vim
Vim Script
13
star
12

vim-wsl-copy-paste

mappings in Vim under WSL to write and read on the Microsoft Windows clipboard
Vim Script
12
star
13

vim-mailquery

complete e-mail addresses in Vim by those found in your Inbox or Sent (or any other mail) folder
Vim Script
12
star
14

vim-select-replace

A Vim plug-in to replace or delete a word or selection in multiple places
Vim Script
9
star
15

vim-unicode-homoglyphs

Highlight and normalize unicode homoglyphs in Vim.
Vim Script
9
star
16

mutt-alias.sh

adds mutt aliases for all recent e-mail addresses found in the Inbox or Sent (or any other mail) folder
Shell
7
star
17

vim-notmuch-addrlookup

complete e-mail addresses in Vim by those found in your Inbox or Sent (or any other mail) folder
Vim Script
6
star
18

backup2cloud.sh

rsync backup script from home folder to rsync server
Shell
4
star
19

vim-taco

Tiny and fully customizable Tab-Completer for Vim
Vim Script
3
star
20

mutt-trim

unclutter and normalize quoted text in an e-mail
Perl
3
star
21

pdf-command-line-tools

command-line tools to process PDFs in batches
Shell
3
star
22

anacron

run jobs only if the computer is online or on power supply
Shell
3
star
23

backup2usb.sh

shell scripts to backup the home (and root) folder to a USB device via either rsync, fsarchiver or system-tar-and-restore
Shell
2
star
24

pandoc-makefile

a template makefile for compiling markdown files and viewing their output by pandoc
Makefile
2
star
25

symlink-dotfiles.sh

create symbolic links inside ~/ of all dotfiles in ~/.config
Shell
2
star
26

fuzzyfinders.sh

Insert in Bash or ZSH a fuzzily found command-line, file or (recent) directory path at the cursor position.
Shell
2
star
27

vim-fuzzyfinders

A minimalist's generic Vim plug-in for fuzzy finding files or folders
Vim Script
2
star
28

vim-smartbraces

make { and } in Vim jump to the beginning respectively end of the current paragraph
Vim Script
2
star
29

vim-tex2utf8

convert (forth and back) between LaTeX commands and UTF-8 characters in Vim
Vim Script
2
star
30

vim-smartHomeEnd

make <Home> and <End> cycle through screen lines in Vim
Vim Script
1
star
31

zathist.sh

Fuzzy find (and open) from `rofi` (or `dmenu`) a PDF file in the history of the zathura viewer.
Shell
1
star
32

opensuse-distribution-upgrade.sh

A simple shell script to automatically upgrade OpenSUSE
Shell
1
star
33

vim-thesauri

A couple of thesaurus files for Vim synomym completion
1
star
34

vim-AutoCorrect

autocorrect spelling mistakes in Vim
Vim Script
1
star
35

cmd-aliases.bat

A few 'aliases' for Microsoft Windows' cmd prompt for fuzzy finding, grepping, ...; implemented as batch files.
Batchfile
1
star
36

vim-keyword-lookup

rapidly look up the meaning of keywords in many script and config files from Vim
Vim Script
1
star
37

complete-common-words.vim

make Vim's dictionary completion suggest the most common words first
Vim Script
1
star
38

matchit-for-markup.vim

vim-matchit settings for pairs of delimiters in markup languages or prose
Vim Script
1
star
39

konfekt.github.io

HTML
1
star