{"id":13898293,"url":"https://github.com/LucHermitte/VimFold4C","last_synced_at":"2025-07-17T15:33:04.009Z","repository":{"id":20912214,"uuid":"24200028","full_name":"LucHermitte/VimFold4C","owner":"LucHermitte","description":"Vim folding ftplugin for C \u0026 C++ (and similar langages)","archived":false,"fork":false,"pushed_at":"2018-11-06T17:10:17.000Z","size":1110,"stargazers_count":38,"open_issues_count":8,"forks_count":6,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-08-07T18:45:51.224Z","etag":null,"topics":["cpp","folding-plugin","vim","vim-plugins"],"latest_commit_sha":null,"homepage":null,"language":"Vim script","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LucHermitte.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-09-18T18:29:58.000Z","updated_at":"2024-04-02T17:08:47.000Z","dependencies_parsed_at":"2022-08-29T10:10:39.374Z","dependency_job_id":null,"html_url":"https://github.com/LucHermitte/VimFold4C","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LucHermitte%2FVimFold4C","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LucHermitte%2FVimFold4C/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LucHermitte%2FVimFold4C/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LucHermitte%2FVimFold4C/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LucHermitte","download_url":"https://codeload.github.com/LucHermitte/VimFold4C/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226274770,"owners_count":17598860,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp","folding-plugin","vim","vim-plugins"],"created_at":"2024-08-06T18:04:12.939Z","updated_at":"2024-11-25T04:31:10.619Z","avatar_url":"https://github.com/LucHermitte.png","language":"Vim script","funding_links":[],"categories":["Vim Script"],"sub_categories":[],"readme":"VimFold4C\n=========\n\nReactive vim fold plugin for C \u0026amp; C++ (and similar languages).\n\nUnlike folding on\n[syntax](http://vimhelp.appspot.com/fold.txt.html#fold%2dsyntax) or on\n[indent](http://vimhelp.appspot.com/fold.txt.html#fold%2dindent), this script\ntries to correctly detect the fold boundaries.\n\n[![Last release](https://img.shields.io/github/tag/LucHermitte/VimFold4C.svg)](https://github.com/LucHermitte/VimFold4C/releases) [![Project Stats](https://www.openhub.net/p/21020/widgets/project_thin_badge.gif)](https://www.openhub.net/p/21020)\n\n## Features\n\nThe foldtext displayed will also try to be as pertinent as possible:\n- Correctly indented\n- Strip spaces in parenthesis\n- Strip `scopes::` (optional)\n- Multiple subsequent (consecutive ?) `#include` will be condensed into one line\n- `#if` \u0026 co are folded\n- When the fold text line to display is too long, simplifications are operated:\n    - Template parameters may be discarded\n    - Initialisation-lists are replaced with  `....`\n    - Parameter names are discarded (this requires [lh-cpp](https://github.com/LucHermitte/lh-cpp)).\n    - Last parameters are discarded \n- fold any instruction, or declaration, spanning on several lines (`cout`,\n  `printf`, `log(stuff \u003c\u003c stuff)`\n\n\n## Note\nIn order to keep the plugin reactive, I had to introduce a few hacks that\ndiminish the precision of the incremental algorithm used to detect fold\nboundaries.  \nAs a consequence, sometimes lines are folded in a very strange way.  \nIn order to fix it, use `zx` or `zX` to reset all fold boundaries.\n\n## Demo\n\nHere is a little screencast to see how things are displayed with VimFold4C.\n\n![VimFold4C demo](doc/screencast-vim-fold.gif \"VimFold4C demo\")\n\nNote: the code comes from unrelated\n[experiment of mine](https://github.com/LucHermitte/NamedParameter).\n\n## Options\n\n### How to set them (syntax)\n\nYou can set local or global options to tune the behaviour of this fold-plugin.\n```vim\n\" In the .vimrc\nlet g:fold_options = {\n   \\ 'fallback_method' : { 'line_threshold' : 2000, 'method' : 'syntax' },\n   \\ 'fold_blank': 0,\n   \\ 'fold_includes': 0,\n   \\ 'max_foldline_length': 'win',\n   \\ 'merge_comments' : 1,\n   \\ 'show_if_and_else': 1,\n   \\ 'strip_namespaces': 1,\n   \\ 'strip_template_arguments': 1\n   \\ }\n```\nor from a [local_vimrc plugin](https://github.com/LucHermitte/local_vimrc):\n```vim\nlet b:fold_options = {\n   \\ 'fallback_method' : { 'line_threshold' : 2000, 'method' : 'syntax' },\n   \\ 'fold_blank': 1,\n   \\ 'fold_includes': 1,\n   \\ 'ignored_doxygen_fields': ['class', 'ingroup', 'function', 'def', 'defgroup', 'exception', 'headerfile', 'namespace', 'property', 'fn', 'var'],\n   \\ 'max_foldline_length': 'win',\n   \\ 'merge_comments' : 0,\n   \\ 'show_if_and_else': 1,\n   \\ 'strip_namespaces': 1,\n   \\ 'strip_template_arguments': 1\n   \\ }\n\n```\n\n### Available options\nThe\n[options](https://github.com/LucHermitte/lh-vim-lib/blob/master/doc/Options.md) are:\n\n- `fallback_method` (default: `{'line_threshold': 0}`) tells to use another\n  fold method when the number of lines in the current file is greater to the\n  given threshold.  \n  In that case use `fallback_method.method` on the current buffer as\n  [fold method](http://vimhelp.appspot.com/options.txt.html#%27foldmethod%27)\n  -- (default: [`\"syntax\"`](http://vimhelp.appspot.com/fold.txt.html#fold%2dsyntax)).  \n  This option is ignored if the threshold equals 0.\n\n- `fold_blank` (default: _true_) tells to fold blanks lines with the lines\n  preceding them.\n\n- `fold_includes` (default: _true_) tells to fold blocks of `#include` directives.\n\n- `ignored_doxygen_fields` (default: `['class', 'ingroup', 'function', 'def',\n  'defgroup', 'exception', 'headerfile', 'namespace', 'property', 'fn',\n  'var']`) list of doxygen keywords that shall be ignored when computing the\n  folded text -- when `merge_comments == 0`\n\n- `max_foldline_length` (default: _\"win\"_) specifies the maximum line length\n  of the fold text. The possibile values are: \n  - _\"win\"_: stops at current window width\n  - _\"tw\"_: stops at current [`'textwidth'`](http://vimhelp.appspot.com/options.txt.html#%27tw%27) column\n  - number: hardcoded maximum number of characters to keep.\n\n- `merge_comments` (default: 1) specifies whether comments shall be folded\n  together with the code or separativelly.\n\n- `strip_namespaces` (default: _true_) tells to strip scopes like `std::` or\n  `boost::filesystem::` from the fold text generated.\n\n- `strip_template_arguments` (default: _true_) strips template arguments from\n  the fold text generated if the text would be too long for the current window\n  width\n\n- `show_if_and_else` (which is currently hard-coded to _true_) requires to have\n  two folds on\n\n    ```c\n    if (foo) {\n        foo_action();\n    } else {\n        bar_action();\n    }\n    ```\n\n    instead of the single fold we have when using `indent` _foldmethod_ (or was it\n    the `syntax` one ?).\n\n#### Note\nDo not set the\n[`'foldmethod'`](http://vimhelp.appspot.com/options.txt.html#%27foldmethod%27)\noption in a ftplugin, or in an autocommand. VimFold4C already takes care of\nsetting it to [`expr`](http://vimhelp.appspot.com/fold.txt.html#fold%2dexpr).\n\n## Requirements / Installation\n\n  * Requirements: Vim 7.+, [lh-vim-lib](http://github.com/LucHermitte/lh-vim-lib) 4.2.0+\n\n  * With [vim-addon-manager](https://github.com/MarcWeber/vim-addon-manager), install VimFold4C.\n\n    ```vim\n    ActivateAddons VimFold4C\n    ```\n\n  * or with [vim-flavor](http://github.com/kana/vim-flavor) which also supports\n    dependencies:\n\n    ```\n    flavor 'LucHermitte/VimFold4C'\n    ```\n\n  * When installing [lh-cpp](http://github.com/LucHermitte/lh-cpp) with\n    [vim-addon-manager](https://github.com/MarcWeber/vim-addon-manager), or\n    other plugin managers based on\n    [vim-pi](https://bitbucket.org/vimcommunity/vim-pi), or with\n    [vim-flavor](http://github.com/kana/vim-flavor) this fold-plugin will get\n    automatically installed.\n\n    ```vim\n    ActivateAddons lh-cpp\n    \" Or just this one (and soon as I register it in vim-pi):\n    ActivateAddons VimFold4C\n    ```\n\n    This is the preferred method because of the various dependencies, and\n    because VimFold4C will do a better job if lh-cpp is installed and detected.\n\n  * or with Vundle/NeoBundle (expecting I haven't forgotten anything):\n\n    ```vim\n    Bundle 'LucHermitte/lh-vim-lib'\n    Bundle 'LucHermitte/VimFold4C'\n    ```\n\nSo far, it is only triggered for C and C++. It should be easy to use it from\nC#, Java, and other languages with C like syntax: a\n\n```vim\nruntime ftplugin/c/c-fold.vim\n```\n\nfrom a C#/Java/... ftplugin should do the trick.\n\nHowever, I'm unlikely to handle specials cases in those languages.\n\n## TO DO\nThere is still a lot to be done:\n\n- [optional] Fold visibilities\n- `#include`\n  - [optional] cut the foldtext line when it's too long to fit\n  - [optional] strip the dirname of each included file to build the foldtext\n    line.\n- Comments\n  - Correctly handle comments for fold boundaries detection\n  - [optional] when there is a leading comment, add a summary at the end of the\n    fold text\n  - [optional] support a policy for comments handling (integrated to the\n    following fold, independent fold, not folded)\n  - use @doxygen tags to build comments foldtext\n  - File headers shall have a special treatment -\u003e detect\n    copyrights/licence/... to build the foldtext\n- Tests\n  - Test, Test, and re-test!\n  - Test with C++11 lambdas\n- Control statements\n  - `switch`/`case`\n    - increment foldlevel for every `case`\n    - [optional] merge `case`s that aren't separated by a `break;`\n  - `do { } while();` requires a specific handling\n\n## History\n- A long time ago (~2001), Johannes Zellner published a first folding plugin\n  for C \u0026 C++.\n- Then, I did some changes (2002-2004), but the result was very slow at the\n  time. (the last version is still archived in\n  \u003chttp://hermitte.free.fr/vim/ressources/lh-cpp.tar.gz\u003e)\n- Eventually I got tired of the slow execution times and moved back to\n  `foldmethod=indent`.\n\n- Here is a new (2014) version almost entirely rewritten, that I hope will\n  be fast enough to be usable.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLucHermitte%2FVimFold4C","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FLucHermitte%2FVimFold4C","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLucHermitte%2FVimFold4C/lists"}