diff --git a/doc/vimwiki.txt b/doc/vimwiki.txt index db6a93e..92ce907 100644 --- a/doc/vimwiki.txt +++ b/doc/vimwiki.txt @@ -2458,6 +2458,8 @@ Limitations: - 'list' is intended to work with lists nicely indented with 'shiftwidth'. - 'syntax' is only available for the default syntax so far. +The options above can be suffixed with ':quick' (e.g.: 'expr:quick') in order +to use some workarounds to make folds work faster. ------------------------------------------------------------------------------ *g:vimwiki_list_ignore_newline* diff --git a/plugin/vimwiki.vim b/plugin/vimwiki.vim index 7baae51..fe2cb80 100644 --- a/plugin/vimwiki.vim +++ b/plugin/vimwiki.vim @@ -147,18 +147,18 @@ endfunction " Vimwiki buffer. function! s:set_windowlocal_options() let foldmethod = vimwiki#vars#get_global('folding') - if foldmethod ==? 'expr' + if foldmethod =~? '^expr.*' setlocal foldmethod=expr setlocal foldexpr=VimwikiFoldLevel(v:lnum) setlocal foldtext=VimwikiFoldText() - elseif foldmethod ==? 'list' || foldmethod ==? 'lists' + elseif foldmethod =~? '^list.*' || foldmethod =~? '^lists.*' setlocal foldmethod=expr setlocal foldexpr=VimwikiFoldListLevel(v:lnum) setlocal foldtext=VimwikiFoldText() - elseif foldmethod ==? 'syntax' + elseif foldmethod =~? '^syntax.*' setlocal foldmethod=syntax setlocal foldtext=VimwikiFoldText() - elseif foldmethod ==? 'custom' + elseif foldmethod =~? '^custom.*' " do nothing else setlocal foldmethod=manual @@ -229,6 +229,16 @@ augroup vimwiki exe 'autocmd InsertLeave *'.s:ext.' call vimwiki#tbl#format(line("."))' exe 'autocmd InsertEnter *'.s:ext.' call vimwiki#tbl#reset_tw(line("."))' endif + if vimwiki#vars#get_global('folding') =~? ':quick$' + " from http://vim.wikia.com/wiki/Keep_folds_closed_while_inserting_text + " Don't screw up folds when inserting text that might affect them, until + " leaving insert mode. Foldmethod is local to the window. Protect against + " screwing up folding when switching between windows. + exe 'autocmd InsertEnter *'.s:ext.' if !exists("w:last_fdm") | let w:last_fdm=&foldmethod'. + \ ' | setlocal foldmethod=manual | endif' + exe 'autocmd InsertLeave,WinLeave *'.s:ext.' if exists("w:last_fdm") |'. + \ 'let &l:foldmethod=w:last_fdm | unlet w:last_fdm | endif' + endif endfor augroup END