Home

Awesome

VimFold4C

Reactive vim fold plugin for C & C++ (and similar languages).

Unlike folding on syntax or on indent, this script tries to correctly detect the fold boundaries.

Last release Project Stats

Features

The foldtext displayed will also try to be as pertinent as possible:

Note

In order to keep the plugin reactive, I had to introduce a few hacks that diminish the precision of the incremental algorithm used to detect fold boundaries.
As a consequence, sometimes lines are folded in a very strange way.
In order to fix it, use zx or zX to reset all fold boundaries.

Demo

Here is a little screencast to see how things are displayed with VimFold4C.

VimFold4C demo

Note: the code comes from unrelated experiment of mine.

Options

How to set them (syntax)

You can set local or global options to tune the behaviour of this fold-plugin.

" In the .vimrc
let g:fold_options = {
   \ 'fallback_method' : { 'line_threshold' : 2000, 'method' : 'syntax' },
   \ 'fold_blank': 0,
   \ 'fold_includes': 0,
   \ 'max_foldline_length': 'win',
   \ 'merge_comments' : 1,
   \ 'show_if_and_else': 1,
   \ 'strip_namespaces': 1,
   \ 'strip_template_arguments': 1
   \ }

or from a local_vimrc plugin:

let b:fold_options = {
   \ 'fallback_method' : { 'line_threshold' : 2000, 'method' : 'syntax' },
   \ 'fold_blank': 1,
   \ 'fold_includes': 1,
   \ 'ignored_doxygen_fields': ['class', 'ingroup', 'function', 'def', 'defgroup', 'exception', 'headerfile', 'namespace', 'property', 'fn', 'var'],
   \ 'max_foldline_length': 'win',
   \ 'merge_comments' : 0,
   \ 'show_if_and_else': 1,
   \ 'strip_namespaces': 1,
   \ 'strip_template_arguments': 1
   \ }

Available options

The options are:

Note

Do not set the 'foldmethod' option in a ftplugin, or in an autocommand. VimFold4C already takes care of setting it to expr.

Requirements / Installation

So far, it is only triggered for C and C++. It should be easy to use it from C#, Java, and other languages with C like syntax: a

runtime ftplugin/c/c-fold.vim

from a C#/Java/... ftplugin should do the trick.

However, I'm unlikely to handle specials cases in those languages.

TO DO

There is still a lot to be done:

History