开发者

vim folds open up when giving an unmatched opening brace/parenthesis

I often come across the situation where I have lots of lines folded and I am writing, say a new block of code, above these folds. As soon as I type a '{', all the folds below open up. Even though it is legitimate th开发者_开发知识库at vim does this, it is irritating to close all the folds again. Is there a way around this situation?


I had the same problem and could solve it using this vimtip.

Little excerpt of the tip description:

If you are using any sort of automatic folding method, be it marker, syntax, or expression folding, inserting text that starts a fold will automatically open all folds beneath the insertion point. This can be very annoying. To get around this, you can temporarily switch to a manual fold method when entering insert mode, and switch back when leaving it.

The trick is to set the foldmethod to manual when editing starts:

autocmd InsertEnter * if !exists('w:last_fdm') | let w:last_fdm=&foldmethod | setlocal foldmethod=manual | endif

When you're done with editing, reset foldmethod to it's original value:

autocmd InsertLeave,WinLeave * if exists('w:last_fdm') | let &l:foldmethod=w:last_fdm | unlet w:last_fdm | endif
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜