Neovim for Beginners — Code Folding
Learn the basics of folding and how to configure treesitter and LSP-based code folding.
In this article, we will learn the basics of folding and how to configure treesitter and LSP-based code folding.
This article is part of the Neovim for Beginners series.
The Neovim configuration files can be found in this repository.
The fastest way to understand folding is to spend a few minutes going through the Vim manual (
:h usr_28.txt). We will only go through the basics here.
:h 'foldmethod’) defines the kind of folding used for the current window. Possible values for this option are
:h fold-manual) — Folds are created manually.
:h fold-indent) — Lines with equal indent form a fold.
:h fold-expr) —
foldexprgives the fold level of a line.
:h fold-marker) — Markers are used to specify folds.
:h fold-syntax) — Syntax highlighting items specify folds.
:h fold-diff) — Fold text that is not changed.
E.g. in the screenshot below, we fold the lines based on the indentation.
In the screenshot below, we fold the paragraphs separated by blank lines.
foldlevel option (
:h 'foldlevel') sets the fold level. Folds with a higher level will be closed. Setting this option to zero will close all folds…