Sunday, November 28, 2010

Re: syntax folding: unfolds all when { is inserted

On Sun, 28 Nov 2010, fkater wrote:

> Hi,
>
> I am using syntax foldling in C files. When all is folded but then a
> somewhere in the middle a { is inserted, every fold below in the file
> gets unfolded (sometimes it returns to the previous state when the
> closing } is inserted, but sometimes not).
>
> I would like to disable this feature if possible, however, keep syntax
> based folding. In case it is related to brace matching I do not need
> that either.
>
> Is there a way?

I asked the same thing a while back[1]. In the end, Bram explained that
it's slightly complicated to get this right[2]. Personally, I use this
variant of Matt's workaround[3] in my own .vimrc:

" Don't update folds in insert mode
aug NoInsertFolding
au!
au InsertEnter * let b:oldfdm = &l:fdm | setl fdm=manual
au InsertLeave * let &l:fdm = b:oldfdm
aug END

The gist: switch to something other than foldmethod=syntax while in
insert mode, then switch back afterward. It still has the problem that
if you insert a bracket and then insert the closing bracket at two
different times (e.g. to add a level of scope to something), the folds
get messed up. But, it's better than the complete craziness of updating
the folds as you're entering them in the first place.

--
Best,
Ben

[1] http://groups.google.com/group/vim_use/browse_thread/thread/9f4c69b6693e8838/e09183be3126b98f
[2] http://groups.google.com/group/vim_use/browse_thread/thread/9f4c69b6693e8838/e09183be3126b98f#9c388b82e879e4fa
[3] http://groups.google.com/group/vim_use/browse_thread/thread/9f4c69b6693e8838/e09183be3126b98f#e09183be3126b98f

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment