{"id":13927078,"url":"https://github.com/pseewald/vim-anyfold","last_synced_at":"2025-04-09T19:19:28.236Z","repository":{"id":44883702,"uuid":"66502942","full_name":"pseewald/vim-anyfold","owner":"pseewald","description":"Language agnostic vim plugin for folding and motion based on indentation.","archived":false,"fork":false,"pushed_at":"2022-01-20T18:36:09.000Z","size":99,"stargazers_count":273,"open_issues_count":13,"forks_count":12,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-09T19:19:24.670Z","etag":null,"topics":["code-display","vim","vim-plugins"],"latest_commit_sha":null,"homepage":"","language":"Vim script","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pseewald.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-08-24T22:01:38.000Z","updated_at":"2025-04-02T06:29:54.000Z","dependencies_parsed_at":"2022-08-26T11:32:10.339Z","dependency_job_id":null,"html_url":"https://github.com/pseewald/vim-anyfold","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pseewald%2Fvim-anyfold","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pseewald%2Fvim-anyfold/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pseewald%2Fvim-anyfold/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pseewald%2Fvim-anyfold/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pseewald","download_url":"https://codeload.github.com/pseewald/vim-anyfold/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248094991,"owners_count":21046770,"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":["code-display","vim","vim-plugins"],"created_at":"2024-08-07T16:01:23.455Z","updated_at":"2025-04-09T19:19:28.209Z","avatar_url":"https://github.com/pseewald.png","language":"Vim script","readme":"# vim-anyfold\n\nGeneric folding mechanism and motion based on indentation. Fold anything that is structured into indented blocks. Quickly navigate between blocks.\n\n\n## Short Instructions\n\nUsing this plugin is easy: Activate vim-anyfold by the command `:AnyFoldActivate` and deal with folds using Vim's built-in fold commands. Use key combinations `[[` and `]]` to navigate to the beginning and end of the current open fold. Use `]k` and `[j` to navigate to the end of the previous block and to the beginning of the next block. For more detailed documentation, read the included vim doc `:h anyfold` or continue reading.\n\n\n## Introduction\n\nThis Vim plugin comes with the following features:\n* Folding mechanism based on indented blocks that has a very intuitive and predictable behaviour (see examples below).\n* Results comparable to syntax aware folding methods but fast and generic algorithm that does not rely on language specific rules.\n* Works out of the box for any filetypes, optimal results for all indented languages (including properly indented curly brace languages).\n* Shortcuts to navigate to beginning / end of a block and to previous / next indented block.\n* Can handle corner cases with ease (comments, varying indentation widths, line breaks).\n* Fast update mechanism that keeps folds in sync with buffer.\n\nIt has the following shortcomings:\n* Can **not** correctly fold mismatched indentation and thus should only be used together with disciplined programming style (or in combination with Vim's `equalprg` autoindent feature).\n\n\n## Advantages over foldmethod=indent\n\n* `foldmethod=indent` only works for indents that are a multiple of `shiftwidth` and thus fails for aligned code lines and inconsistent indentation. Vim-anyfold correctly defines folds for arbitrary indents.\n* vim-anyfold recognizes braces as part of indented blocks and correctly folds them. Vim-anyfold thus produces good folds not only for indented languages but also for e.g. C++ or Java.\n* vim-anyfold optionally folds multiline comments.\n\nBe aware that `vim-anyfold` is much slower than `foldmethod=indent` and can reduce Vim's responsiveness. This is noticeable only when editing large files.\n\n\n## Examples\n\n### Python\n![python](https://cloud.githubusercontent.com/assets/6178172/18611583/c489caa8-7d3d-11e6-8a12-57fe183250ed.gif)\n\n### Fortran\n![fortran](https://cloud.githubusercontent.com/assets/6178172/18611581/c4865c92-7d3d-11e6-9a90-98bbb12d04d5.gif)\n\n### C++\n![cpp](https://cloud.githubusercontent.com/assets/6178172/18611584/c48a3c86-7d3d-11e6-9d64-df01580709ae.gif)\n\n### Java\nNote: this example is outdated since better defaults have been implemented for curly braces.\n![java](https://cloud.githubusercontent.com/assets/6178172/18611582/c4896374-7d3d-11e6-834b-9dcecb4ae1ef.gif)\n\nExamples were recorded using\n\n```vim\nautocmd Filetype * AnyFoldActivate\nlet g:anyfold_fold_comments=1\nset foldlevel=0\ncolorscheme solarized\nhi Folded term=NONE cterm=NONE\n```\n\n\n## Setup and usage\n\n1. Install this plugin with a vim plugin manager.\n2. Add the following lines to your vimrc (if not already present).\n\n    ```vim\n    filetype plugin indent on \" required\n    syntax on                 \" required\n\n    autocmd Filetype * AnyFoldActivate               \" activate for all filetypes\n    \" or\n    autocmd Filetype \u003cyour-filetype\u003e AnyFoldActivate \" activate for a specific filetype\n\n    set foldlevel=0  \" close all folds\n    \" or\n    set foldlevel=99 \" Open all folds\n    ```\n\nIf you prefer to not activate vim-anyfold automatically, you can always invoke this plugin manually inside vim by typing `:AnyFoldActivate`.\n\n3. Use Vim's fold commands `zo`, `zO`, `zc`, `za`, ... to fold / unfold folds (read `:h fold-commands` for more information). Use key combinations `[[` and `]]` to navigate to the beginning and end of the current open fold. Use `]k` and `[j` to navigate to the end of the previous block and to the beginning of the next block.\n\n\n## Additional remarks\n\n1. *Supported folding commands:* anyfold uses `foldmethod=expr` to define folds. Thus all commands that work with expression folding are supported.\n2. *Fold display:* anyfold's minimalistic display of closed fold assumes that folds are highlighted by your color scheme. If that is not the case, consider installing a suitable color scheme or highlight folds yourself by a command similar to\n\n    ```vim\n    hi Folded term=underline\n    ```\n\n3. *Lines to ignore:* By default, anyfold uses the `foldignore` option to identify lines to ignore (such as comment lines and preprocessor statements). Vim's default is `foldignore = #`. Lines starting with characters in `foldignore` will get their fold level from surrounding lines. If `anyfold_fold_comments = 1` these lines get their own folds. For instance, in order to ignore C++ style comments starting with `//` and preprocessor statements starting with `#`, set\n\n    ```vim\n    autocmd Filetype cpp set foldignore=#/\n    ```\n    This approach is fast but does not work for e.g. C style multiline comments and Python doc strings. If you'd like anyfold to correctly ignore these lines, add\n\n    ```vim\n    let g:anyfold_identify_comments=2\n    ```\n    to your vimrc. Please note that this may considerably slow down your Vim performance (mostly when opening large files).\n4. *Large Files:* anyfold causes long load times on large files, significantly longer than plain indent folding. By adding the following to your vimrc (and replacing `\u003cfiletype\u003e`), anyfold is not initialized for large files:\n\n    ```vim\n    \" activate anyfold by default\n    augroup anyfold\n        autocmd!\n        autocmd Filetype \u003cfiletype\u003e AnyFoldActivate\n    augroup END\n\n    \" disable anyfold for large files\n    let g:LargeFile = 1000000 \" file is large if size greater than 1MB\n    autocmd BufReadPre,BufRead * let f=getfsize(expand(\"\u003cafile\u003e\")) | if f \u003e g:LargeFile || f == -2 | call LargeFile() | endif\n    function LargeFile()\n        augroup anyfold\n            autocmd! \" remove AnyFoldActivate\n            autocmd Filetype \u003cfiletype\u003e setlocal foldmethod=indent \" fall back to indent folding\n        augroup END\n    endfunction\n\n    ```\n\n5. *Customization:* For expert configuration, anyfold triggers an event `anyfoldLoaded` after initialisation. This enables user-defined startup steps such as\n\n    ```vim\n    autocmd User anyfoldLoaded normal zv\n    ```\n\n   which unfolds the line in which the cursor is located when opening a file.\n6. *Documentation:* For more detailed instructions and information, read the included vim doc `:h anyfold`.\n\n\n## Options\n\nAll options can be either set globally\n\n```vim\nlet g:\u003coption\u003e=\u003cvalue\u003e\n```\n\nor filetype specific\n\n```vim\nautocmd Filetype \u003cfiletype\u003e let g:\u003coption\u003e=\u003cvalue\u003e\n```\n\nOption | Values | Default value |  Description\n------ | -------------- | ------------- | ------------\n`anyfold_fold_display` | 0, 1 | 1 | Minimalistic display of closed folds\n`anyfold_motion` | 0, 1 | 1 | Map motion commands to `[[`, `]]`, `[j`, `]k`\n`anyfold_identify_comments` | 0, 1, 2 | 1 | Identify lines to ignore for better fold behavior. 1: use `foldignore`, 2: use `foldignore` and syntax (slow)\n`anyfold_fold_comments` | 0, 1 | 0 | Fold multiline comments\n`anyfold_comments` | list of strings | ['comment', 'string'] | Names of syntax items that should be ignored. Only used if `anyfold_identify_comments = 2`.\n`anyfold_fold_toplevel` | 0, 1 | 0 | Fold subsequent unindented lines\n`anyfold_fold_size_str` | string | '%s lines' | Format of fold size string in minimalistic display\n`anyfold_fold_level_str` | string | ' + ' | Format of fold level string in minimalistic display\n\n## Complementary plugins\n\nHere is a small list of plugins that I find very useful in combination with vim-anyfold:\n* Cycle folds with one key, much more efficient than Vim's built-in folding commands: [vim-fold-cycle](https://github.com/arecarn/vim-fold-cycle)\n* Indent based text objects are not (yet) implemented in vim-anyfold, but this plugin works fine (even though blocks are defined in a slightly different way): [vim-indent-object](https://github.com/michaeljsmith/vim-indent-object)\n\n\n## Acknowledgements\n\nI thank the following people for their contribution\n* Greg Sexton for allowing me to use [his function](http://gregsexton.org/2011/03/27/improving-the-text-displayed-in-a-vim-fold.html) for improved fold display.\n","funding_links":[],"categories":["Vim Script"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpseewald%2Fvim-anyfold","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpseewald%2Fvim-anyfold","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpseewald%2Fvim-anyfold/lists"}