├── .gitignore ├── README.md ├── doc └── FastFold.txt └── plugin └── fastfold.vim /.gitignore: -------------------------------------------------------------------------------- 1 | doc/tags 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # What good will FastFold do? 2 | 3 | Automatic folds (that is, folds generated by a fold method different 4 | from `manual`), bog down VIM noticeably in insert mode. They are also often 5 | recomputed too early (for example, when inserting an opening fold marker 6 | whose closing counterpart is yet missing to complete the fold.) 7 | 8 | See http://vim.wikia.com/wiki/Keep_folds_closed_while_inserting_text 9 | for a discussion. 10 | 11 | With this plug-in, the folds in the currently edited buffer are updated by an 12 | automatic fold method only 13 | 14 | - when saving the buffer 15 | - when closing or opening folds (zo, za, zc, etc...) 16 | - when moving or operating fold-wise (zj,zk,[z,]z) 17 | - when typing `zuz` in normal mode 18 | 19 | and are kept as is otherwise (by keeping the fold method set to `manual`). 20 | 21 | # Example Setup 22 | 23 | Each of these triggers for updating folds can be modified or disabled by adding 24 | the lines 25 | 26 | ```vim 27 | nmap zuz (FastFoldUpdate) 28 | let g:fastfold_savehook = 1 29 | let g:fastfold_fold_command_suffixes = ['x','X','a','A','o','O','c','C'] 30 | let g:fastfold_fold_movement_commands = [']z', '[z', 'zj', 'zk'] 31 | ``` 32 | 33 | to the file `~/.vimrc` (respectively `%USERPROFILE%/_vimrc` on Microsoft Windows). 34 | 35 | For example, by adding 36 | 37 | ```vim 38 | let g:markdown_folding = 1 39 | let g:rst_fold_enabled = 1 40 | let g:tex_fold_enabled = 1 41 | let g:vimsyn_folding = 'af' 42 | let g:xml_syntax_folding = 1 43 | let g:javaScript_fold = 1 44 | let g:sh_fold_enabled= 7 45 | let g:zsh_fold_enable = 1 46 | let g:ruby_fold = 1 47 | let g:perl_fold = 1 48 | let g:perl_fold_blocks = 1 49 | let g:r_syntax_folding = 1 50 | let g:rust_fold = 1 51 | let g:php_folding = 1 52 | let g:fortran_fold=1 53 | let g:clojure_fold = 1 54 | let g:baan_fold=1 55 | ``` 56 | 57 | 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. 58 | (Likewise, in a `Markdown`, `RST` or `Rust` file, by the `expression` fold method.) 59 | Syntax folding for `C` and `C++` files can be enabled by adding 60 | 61 | ```vim 62 | autocmd FileType c,cpp setlocal foldmethod=syntax 63 | ``` 64 | 65 | to your `vimrc` (see `:help ft-c-syntax`). 66 | For Python, adding 67 | 68 | ```vim 69 | autocmd FileType python setlocal foldmethod=indent 70 | ``` 71 | 72 | to your `vimrc` mostly suffices, though installing [SimplyFold](https://github.com/tmhedberg/SimpylFold) refines folds from successive indent levels to syntax objects such as functions. 73 | 74 | # Configuration 75 | 76 | - If you prefer that folds are only updated manually but not when saving the buffer, 77 | then add `let g:fastfold_savehook = 0` to your `.vimrc`. 78 | 79 | - If you prefer that folds are not updated whenever you close or open folds by a 80 | standard keystroke such as `zx`,`zo` or `zc`, then add `let 81 | g:fastfold_fold_command_suffixes = []` to your `.vimrc`. 82 | 83 | The exact list of these standard keystrokes is `zx,zX,za,zA,zo,zO,zc,zC` and 84 | it can be customized by changing the global variable 85 | `g:fastfold_mapsuffixes`. If you wanted to intercept all possible fold 86 | commands (such as zr,zm,...), change this to: 87 | 88 | ```vim 89 | let g:fastfold_fold_command_suffixes = 90 | ['x','X','a','A','o','O','c','C','r','R','m','M','i','n','N'] 91 | ``` 92 | 93 | - If you prefer that this plug-in does not add a normal mode mapping that updates 94 | folds (that defaults to `zuz`), then add 95 | `nmap (DisableFastFoldUpdate) (FastFoldUpdate) ` to your `.vimrc`. 96 | 97 | You can remap `zuz` to your favorite keystroke, say ``, by adding 98 | `nmap (FastFoldUpdate)` to your `.vimrc`. 99 | 100 | There is also a command `FastFoldUpdate` that updates all folds and its 101 | variant `FastFoldUpdate!` that updates all folds and echos by which fold 102 | method the folds were updated. 103 | 104 | - FastFold by default only prevents the `syntax` fold methods from recomputing 105 | on every buffer change. These can be customized by `g:fastfold_foldmethods` 106 | in your `.vimrc`, for example `g:fastfold_foldmethods = ['syntax', 'expr']` 107 | (equivalent to `let g:fastfold_force = 1`) also applies this to `expr` folds. 108 | This should only be necessary for [inefficient foldexprs, though](https://github.com/lervag/vimtex/pull/3054). 109 | 110 | - FastFold is by default enabled for files that have more than a certain 111 | number of lines, by default set to 200. To change this number, for example, 112 | to enable FastFold independent of the number of lines of a file, add 113 | `let g:fastfold_minlines = 0` to your `.vimrc`. 114 | 115 | # Caveats 116 | 117 | FastFold overwrites your manual folds when saving the currently edited buffer, 118 | unless 119 | 120 | - FastFold is disabled for this filetype by `g:fastfold_skip_filetypes`, or 121 | - the `foldmethod=manual` since having entered the buffer. 122 | 123 | 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`. 124 | For a thorougher solution, install [vim-stay](https://github.com/zhimsel/vim-stay) discussed below. 125 | 126 | # Addons 127 | 128 | ## Vim-Stay 129 | 130 | `FastFold` integrates with the plug-in 131 | [vim-stay](https://github.com/zhimsel/vim-stay) that restores the 132 | folds of a file buffer by `:mkview` and `:loadview`. 133 | 134 | ## Custom Fold Text 135 | 136 | Replace the standard `&foldtext` 137 | 138 | - by [one](http://www.github.com/Konfekt/FoldText) 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](https://web.archive.org/web/20161017143651/http://www.gregsexton.org:80/2011/03/improving-the-text-displayed-in-a-fold/), or 139 | - by [one](https://github.com/kaile256/vim-foldpeek) that previews the most pertinent initial text of the fold (together with the fold level and number of lines). 140 | 141 | ## NrrwRgn 142 | 143 | `FastFold` integrates with the plug-in 144 | [NrrwRgn](https://github.com/chrisbra/NrrwRgn/) that lets you edit a selection in a new temporary buffer by adding to your `vimrc` the line 145 | 146 | ```vim 147 | autocmd BufWinEnter * let b:nrrw_aucmd_create = "let w:lastfdm = getwinvar(winnr('#'), 'lastfdm')" 148 | ``` 149 | 150 | ## Fold Text-Object 151 | 152 | Create a fold text object, mapped to `iz` and `az`, by adding the lines 153 | 154 | ```vim 155 | xnoremap iz :FastFoldUpdate]z$v[z^ 156 | xnoremap az :FastFoldUpdate]zV[z 157 | ``` 158 | 159 | to the file `~/.vimrc` (respectively `%USERPROFILE%/_vimrc` on Microsoft Windows). 160 | 161 | -------------------------------------------------------------------------------- /doc/FastFold.txt: -------------------------------------------------------------------------------- 1 | FastFold, folding optimization *FastFold* *fastfold* 2 | 3 | =========================================================================== 4 | 0. Introduction ~ 5 | *FastFold-intro* *fastfold-intro* 6 | 7 | Automatic folds - that is, folds generated by a fold method different 8 | from manual - bog down VIM considerably in insert mode. Also, they are often 9 | re-evaluated prematurely for example, when inserting an opening fold marker 10 | whose closing counterpart has yet to be added to complete the fold. 11 | 12 | See http://vim.wikia.com/wiki/Keep_folds_closed_while_inserting_text 13 | for a discussion. 14 | 15 | With this plug-in, the folds in the currently edited buffer are updated when 16 | certain triggers are met: 17 | 18 | - when saving the buffer 19 | - when closing or opening folds (zo, za, zc, etc...) 20 | - when moving or operating fold-wise (zj,zk,[z,]z) 21 | - when typing zuz in normal mode 22 | 23 | =========================================================================== 24 | 1. Commands ~ 25 | *FastFold-commands* *fastfold-commands* 26 | *FastFoldUpdate!* 27 | 28 | - :FastFoldUpdate updates all folds in the current buffer. 29 | - :FastFoldUpdate! updates all folds & echoes what fold method was used 30 | 31 | - The mapping zuz that invokes :FastFoldUpdate! can be changed to your 32 | favorite keystroke, say , by adding 33 | > 34 | nmap (FastFoldUpdate) 35 | < 36 | to your .vimrc. It can be disabled by adding 37 | > 38 | nmap (DisableFastFoldUpdate) (FastFoldUpdate) 39 | < 40 | =========================================================================== 41 | 2. Config ~ 42 | *FastFold-config* *fastfold-config* 43 | 44 | Each of the above triggers can be enabled or disabled by setting the 45 | matching global flags in your .vimrc. Default values are shown. 46 | > 47 | let g:fastfold_savehook = 1 48 | let g:fastfold_fdmhook = 0 49 | nmap zuz (FastFoldUpdate) 50 | let g:fastfold_fold_command_suffixes = ['x','X','a','A','o','O','c','C'] 51 | let g:fastfold_fold_movement_commands = [']z', '[z', 'zj', 'zk'] 52 | < 53 | For example, adding the following lines to your .vimrc 54 | > 55 | let g:tex_fold_enabled=1 56 | let g:vimsyn_folding='af' 57 | let g:xml_syntax_folding = 1 58 | let g:javaScript_fold = 1 59 | let g:ruby_fold = 1 60 | let g:sh_fold_enabled= 7 61 | let g:php_folding = 1 62 | let g:perl_fold = 1 63 | < 64 | enables syntax folding for tex, vim, xml, javascript, ruby, shell script and 65 | perl files. 66 | 67 | ----------------------------- 68 | 69 | - All folds are recomputed when you open or close folds by the commands 70 | zx, zX, za, zA, zo, zO, zc, zC. This list of commands is configured by the 71 | variable *g:fastfold_fold_command_suffixes* . To intercept all possible fold 72 | commands (such as zr,zm,...), change it to: 73 | > 74 | let g:fastfold_fold_command_suffixes = 75 | ['x','X','a','A','o','O','c','C','r','R','m','M','i','n','N'] 76 | < 77 | or, to disable all interceptions, to: 78 | > 79 | let g:fastfold_fold_command_suffixes = [] 80 | < 81 | - All folds are recomputed when you move or operate fold-wise by 82 | the commands zj,zk,[z or ]z. This list of commands is configured by 83 | variable *g:fastfold_fold_movement_commands* . To disable all interceptions, 84 | change it to: 85 | > 86 | let g:fastfold_fold_movement_commands = [] 87 | < 88 | - FastFold updates all folds when you save a buffer. To disable this hook, 89 | toggle the default value 1 of the variable *g:fastfold_savehook* by: 90 | > 91 | let g:fastfold_savehook = 0 92 | < 93 | - FastFold by default only prevents the expression and syntax fold methods 94 | from recomputing on every buffer change. To prevent all fold methods (except 95 | manual) from doing so, toggle the default value 0 of *g:fastfold_force* by: 96 | > 97 | let g:fastfold_force = 1 98 | < 99 | - FastFold by default only prevents the |syntax| fold methods from recomputing 100 | on every buffer change. These can be customized by *g:fastfold_foldmethods* 101 | in your *vimrc*, for example > 102 | 103 | let g:fastfold_foldmethods = ['syntax', 'expr'] 104 | < 105 | (equivalent to g:fastfold_force = 1) also applies this to |expr| folds. 106 | This should only be necessary for inefficient foldexprs, though: 107 | 108 | https://github.com/lervag/vimtex/pull/3054 109 | < 110 | - To intercept every change of the fold method, toggle the default value 0 of 111 | *g:fastfold_fdmhook* by: 112 | > 113 | let g:fastfold_fdmhook = 1 114 | < 115 | It is set to zero by default because it could interfere with other plugins, 116 | such as vim-easymotion. 117 | 118 | - To disable FastFold for certain file types, say taglist, change the default 119 | empty value [] of the list *g:fastfold_skip_filetypes* to: 120 | > 121 | let g:fastfold_skip_filetypes = [ 'taglist' ] 122 | < 123 | - FastFold by default only prevents the expression and syntax fold methods 124 | from recomputing on for files that have more than a certain 125 | number of lines. To change the default value of 200 of *g:fastfold_minlines* 126 | to, for example, 0: 127 | > 128 | let g:fastfold_minlines = 0 129 | < 130 | 131 | =========================================================================== 132 | 3. Extra Notes ~ 133 | 134 | You can add a visual fold text-object, mapped to iz and az, by 135 | > 136 | xnoremap iz :FastFoldUpdate:normal! ]zv[z 137 | xnoremap az :FastFoldUpdate:normal! ]zV[z 138 | < 139 | 140 | 3.1 Related Plugins ~ 141 | 142 | FastFold integrates with the plug-in vim-stay available at 143 | 144 | https://github.com/zhimsel/vim-stay 145 | 146 | that stores and restores the last folds by :mkview and :loadview. 147 | 148 | ------------------------------ 149 | 150 | `FastFold` integrates with the plug-in NrrwRgn available at 151 | 152 | https://github.com/chrisbra/NrrwRgn/ 153 | 154 | that lets you edit a selection in a new temporary buffer by adding to your 155 | vimrc the line 156 | > 157 | autocmd BufWinEnter * let b:nrrw_aucmd_create = "let w:lastfdm = getwinvar(winnr('#'), 'lastfdm')" 158 | < 159 | -------------------------------- 160 | 161 | Replace the standard `&foldtext` 162 | 163 | - by one that displays the percentage of the number of buffer lines that the 164 | folded text takes up and indents folds according to their nesting level, 165 | available at http://www.github.com/Konfekt/FoldText, or 166 | - by one that shows the most pertinent initial text of the fold (including fold 167 | level and number of lines), availabe at https://github.com/kaile256/vim-foldpeek 168 | 169 | 3.2 Caveats ~ 170 | 171 | FastFold overwrites your manual folds when saving the currently edited buffer, 172 | unless 173 | 174 | - FastFold is disabled for this filetype by g:fastfold_skip_filetypes, or 175 | - the foldmethod=manual since having entered the buffer. 176 | 177 | To ensure that sessions do not override the default fold method of the buffer 178 | file type (by the value manual), set sessionoptions-=folds in your 179 | vimrc. For a thorougher solution, install vim-stay discussed above. 180 | 181 | 3.3 API ~ 182 | 183 | The last used fold method by which FastFold updates the folds in the current 184 | buffer can be read off from the window local variable w:lastdfm. 185 | 186 | 3.4 Thanks go to... ~ 187 | 188 | - starcraftman for providing this documentation, and 189 | - blueyed, kopischke, sabauma, willywampa, and many others for reporting 190 | issues and suggesting code improvements. 191 | 192 | vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl 193 | -------------------------------------------------------------------------------- /plugin/fastfold.vim: -------------------------------------------------------------------------------- 1 | scriptencoding utf-8 2 | 3 | " LICENCE PUBLIQUE RIEN À BRANLER 4 | " Version 1, Mars 2009 5 | " 6 | " Copyright (C) 2009 Sam Hocevar 7 | " 14 rue de Plaisance, 75014 Paris, France 8 | " 9 | " La copie et la distribution de copies exactes de cette licence sont 10 | " autorisées, et toute modification est permise à condition de changer 11 | " le nom de la licence. 12 | " 13 | " CONDITIONS DE COPIE, DISTRIBUTON ET MODIFICATION 14 | " DE LA LICENCE PUBLIQUE RIEN À BRANLER 15 | " 16 | " 0. Faites ce que vous voulez, j'en ai RIEN À BRANLER. 17 | 18 | if exists('g:loaded_fastfold') || &cp 19 | finish 20 | endif 21 | let g:loaded_fastfold = 1 22 | 23 | let s:keepcpo = &cpo 24 | set cpo&vim 25 | " ------------------------------------------------------------------------------ 26 | 27 | if !exists('g:fastfold_fdmhook') | let g:fastfold_fdmhook = 0 | endif 28 | if !exists('g:fastfold_savehook') | let g:fastfold_savehook = 1 | endif 29 | " translate this setting for backwards compatibility 30 | if get(g:, 'fastfold_force', 0) == 1 31 | let g:fastfold_foldmethods = ['syntax', 'expr'] 32 | else 33 | let g:fastfold_foldmethods = ['syntax'] 34 | endif 35 | if !exists('g:fastfold_skip_filetypes') | let g:fastfold_skip_filetypes = [] | endif 36 | if !exists('g:fastfold_minlines') | let g:fastfold_minlines = 100 | endif 37 | if !exists('g:fastfold_fold_command_suffixes') 38 | let g:fastfold_fold_command_suffixes = ['x','X','a','A','o','O','c','C'] 39 | endif 40 | if !exists('g:fastfold_fold_movement_commands') 41 | let g:fastfold_fold_movement_commands = [']z', '[z', 'zj', 'zk'] 42 | endif 43 | 44 | function! s:EnterWin() 45 | if s:Skip() 46 | if exists('w:lastfdm') 47 | unlet w:lastfdm 48 | endif 49 | else 50 | let w:lastfdm = &l:foldmethod 51 | setlocal foldmethod=manual 52 | endif 53 | endfunction 54 | 55 | function! s:LeaveWin() 56 | if exists('w:predifffdm') 57 | if empty(&l:foldmethod) || &l:foldmethod is# 'manual' 58 | let &l:foldmethod = w:predifffdm 59 | unlet w:predifffdm 60 | return 61 | elseif &l:foldmethod isnot# 'diff' 62 | unlet w:predifffdm 63 | endif 64 | endif 65 | 66 | if exists('w:lastfdm') && &l:foldmethod is# 'diff' 67 | let w:predifffdm = w:lastfdm 68 | endif 69 | 70 | if exists('w:lastfdm') && &l:foldmethod is# 'manual' 71 | let &l:foldmethod = w:lastfdm 72 | endif 73 | endfunction 74 | 75 | " Like windo but restore the current buffer. 76 | " See http://vim.wikia.com/wiki/Run_a_command_in_multiple_buffers#Restoring_position 77 | function! s:WinDo( command ) 78 | " avoid errors in CmdWin 79 | if exists('*getcmdwintype') && !empty(getcmdwintype()) 80 | return 81 | endif 82 | " Work around Vim bug. 83 | " See https://groups.google.com/forum/#!topic/vim_dev/LLTw8JV6wKg 84 | let curaltwin = winnr('#') ? winnr('#') : 1 85 | let currwin=winnr() 86 | if &scrollopt =~# '\' 87 | set scrollopt-=jump 88 | let l:restore = 'set scrollopt+=jump' 89 | endif 90 | " Work around Vim bug. 91 | " See https://github.com/vim/vim/issues/4622#issuecomment-508985573 92 | let l:currwinwidth = &winwidth 93 | let &winwidth = &winminwidth > 0 ? &winminwidth : 1 94 | silent! execute 'keepjumps noautocmd windo ' . a:command 95 | silent! execute 'noautocmd ' . curaltwin . 'wincmd w' 96 | silent! execute 'noautocmd ' . currwin . 'wincmd w' 97 | if exists('l:restore') 98 | exe l:restore 99 | endif 100 | let &winwidth = l:currwinwidth 101 | endfunction 102 | 103 | " WinEnter then TabEnter then BufEnter then BufWinEnter 104 | function! s:UpdateWin() 105 | let s:curwin = winnr() 106 | call s:WinDo('if winnr() is s:curwin | call s:LeaveWin() | endif') 107 | call s:WinDo('if winnr() is s:curwin | call s:EnterWin() | endif') 108 | endfunction 109 | 110 | function! s:UpdateBuf(feedback) 111 | " skip if in TelescopeResults and TelescopePrompt UI buffers 112 | if has('nvim') && &l:filetype[0:8] ==# 'Telescope' | return | endif 113 | 114 | " skip if another session still loading 115 | if exists('g:SessionLoad') | return | endif 116 | 117 | let s:curbuf = bufnr('%') 118 | call s:WinDo("if bufnr('%') is s:curbuf | call s:LeaveWin() | endif") 119 | call s:WinDo("if bufnr('%') is s:curbuf | call s:EnterWin() | endif") 120 | 121 | if !a:feedback | return | endif 122 | 123 | if !exists('w:lastfdm') 124 | echomsg "'" . &l:foldmethod . "' folds already continuously updated" 125 | else 126 | echomsg "updated '" . w:lastfdm . "' folds" 127 | endif 128 | endfunction 129 | 130 | function! s:UpdateTab() 131 | " skip if another session still loading 132 | if exists('g:SessionLoad') | return | endif 133 | 134 | call s:WinDo('call s:LeaveWin()') 135 | call s:WinDo('call s:EnterWin()') 136 | endfunction 137 | 138 | function! s:Skip() 139 | if s:isSmall() | return 1 | endif 140 | if !s:isReasonable() | return 1 | endif 141 | if s:inSkipList() | return 1 | endif 142 | if !empty(&l:buftype)| return 1 | endif 143 | if !&l:modifiable | return 1 | endif 144 | 145 | return 0 146 | endfunction 147 | 148 | function! s:isReasonable() 149 | return index(g:fastfold_foldmethods, &l:foldmethod) >= 0 150 | endfunction 151 | 152 | function! s:inSkipList() 153 | if index(g:fastfold_skip_filetypes, &l:filetype) >= 0 154 | return 1 155 | else 156 | return 0 157 | endif 158 | endfunction 159 | 160 | function! s:isSmall() 161 | if line('$') <= g:fastfold_minlines 162 | return 1 163 | else 164 | return 0 165 | endif 166 | endfunction 167 | 168 | command! -bar -bang FastFoldUpdate call s:UpdateBuf(0) 169 | 170 | nnoremap (FastFoldUpdate) :FastFoldUpdate! 171 | 172 | if !hasmapto('(FastFoldUpdate)', 'n') && empty(mapcheck('zuz', 'n')) 173 | nmap zuz (FastFoldUpdate) 174 | endif 175 | 176 | for suffix in g:fastfold_fold_command_suffixes 177 | execute 'nnoremap z'.suffix.' :call UpdateWin()z'.suffix 178 | endfor 179 | 180 | for cmd in g:fastfold_fold_movement_commands 181 | exe "nnoremap " . cmd. " ':call UpdateWin()'.v:count." . "'".cmd."'" 182 | exe "xnoremap " . cmd. " ':call UpdateWin()gv'.v:count." . "'".cmd."'" 183 | exe "onoremap " . cmd. " ':call UpdateWin()' . '\"' . v:register . v:operator . v:count1 . " . "'".cmd."'" 184 | endfor 185 | 186 | augroup FastFold 187 | autocmd! 188 | autocmd VimEnter * call s:init() 189 | augroup end 190 | 191 | function! s:init() 192 | call s:UpdateTab() 193 | augroup FastFoldEnter 194 | autocmd! 195 | " Make foldmethod local to buffer instead of window 196 | autocmd WinEnter * 197 | \ let w:winenterbuf = bufnr('%') | 198 | \ if exists('b:lastfdm') | 199 | \ let w:lastfdm = b:lastfdm | 200 | \ endif 201 | autocmd BufEnter * 202 | \ if exists('w:winenterbuf') | 203 | \ if w:winenterbuf != bufnr('%') | 204 | \ unlet! w:lastfdm | 205 | \ endif | 206 | \ unlet w:winenterbuf | 207 | \ endif 208 | autocmd WinLeave * 209 | \ if exists('w:lastfdm') | let b:lastfdm = w:lastfdm | 210 | \ elseif exists('b:lastfdm') | unlet b:lastfdm | endif 211 | autocmd WinLeave * 212 | \ if exists('w:predifffdm') | let b:predifffdm = w:predifffdm | 213 | \ elseif exists('b:predifffdm') | unlet b:predifffdm | endif 214 | " Update folds after foldmethod set by filetype autocmd 215 | autocmd FileType * call s:UpdateBuf(0) 216 | " Update folds after foldmethod set by :loadview or :source Session.vim 217 | autocmd SessionLoadPost * call s:UpdateBuf(0) 218 | " Update folds after foldmethod set by modeline 219 | if g:fastfold_fdmhook && exists('##OptionSet') 220 | autocmd OptionSet foldmethod call s:UpdateBuf(0) 221 | autocmd BufRead * call s:UpdateBuf(0) 222 | else 223 | autocmd BufWinEnter * 224 | \ if !exists('b:fastfold') | 225 | \ call s:UpdateBuf(0) | 226 | \ let b:fastfold = 1 | 227 | \ endif 228 | endif 229 | " Update folds after entering a changed buffer 230 | autocmd BufEnter * 231 | \ if !exists('b:lastchangedtick') | let b:lastchangedtick = b:changedtick | endif | 232 | \ if b:changedtick != b:lastchangedtick && (&l:foldmethod isnot# 'diff' && exists('b:predifffdm')) | call s:UpdateBuf(0) | endif 233 | autocmd BufLeave * let b:lastchangedtick = b:changedtick 234 | " Update folds after saving 235 | if g:fastfold_savehook 236 | autocmd BufWritePost * call s:UpdateBuf(0) 237 | endif 238 | augroup end 239 | endfunction 240 | 241 | " ------------------------------------------------------------------------------ 242 | let &cpo= s:keepcpo 243 | unlet s:keepcpo 244 | --------------------------------------------------------------------------------