Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update README.md for better folding settings #5274

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -462,13 +462,29 @@ require'nvim-treesitter.configs'.setup {

Tree-sitter based folding. _(Technically not a module because it's per windows and not per buffer.)_

```lua
vim.o.foldmethod = "expr"
vim.o.foldexpr = "v:lua.vim.treesitter.foldexpr()"
-- With the above settings applied, vim will fold everything by default when
-- opening a file... setting foldlevelstart to a high value allows you to
-- start with no folds and then toggle them as desired with the za keymap.
vim.o.foldlevelstart = 99
```

or if you prefer vimscript:

```vim
set foldmethod=expr
set foldexpr=nvim_treesitter#foldexpr()
set nofoldenable " Disable folding at startup.
set foldexpr=v:lua.vim.treesitter.foldexpr()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Built-in foldexpr seems available from neovim 0.9+ and ported from this repo (neovim/neovim#22299). Does this mean that nvim_treesitter#foldexpr() is deprecated and no longer used?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is correct. (I mentioned that the README is a mess, didn't I?)

set foldlevelstart=99
```

This will respect your `foldminlines` and `foldnestmax` settings.
This will respect your `foldminlines` and `foldnestmax` settings. Once inside
a buffer, you could use `:set foldlevel=2` to collapse all folds above level 2.

Note that this applies these options globally. If you want these settings to
only be set for certain filetypes, then apply the above as window options using
`vim.wo` in a `ftplugin/<filetype>.lua` file or in a `FileType` autocommand.

# Advanced setup

Expand Down