Skip to content

Vim Folds

Resources

Folding based on regex

Let's say you have a paragraph that you want to always get folded in a buffer. Eg. foam adds the following to every page:

[//begin]: # "Autogenerated link references for markdown compatibility"
[vim-wiki]: vim-wiki/vim-wiki.md "Vim Wiki"
[plugins]: ../../../_layouts/node_modules/axe-core/doc/plugins.md "Plugins"
[themes]: themes/themes.md "Themes"
[vimscript]: vimscript/vimscript.md "VimScript"
[vim-resources]: resources/vim-resources.md "Vim Resources"
[awesome-vim]: awesome-vim.md "Awesome Vim"
[neovim]: neovim/neovim.md "NeoVim"
[vim-showcases]: vim-showcases.md "vim-showcases"
[//end]: # "Autogenerated link references"

So, to auto fold the above, you would need:

setlocal foldmarker=[//begin],[//end]
setlocal foldmethod=marker
setlocal foldlevelstart=0