Skip to content

Latest commit

 

History

History
71 lines (62 loc) · 2.16 KB

README.md

File metadata and controls

71 lines (62 loc) · 2.16 KB

nvim-treesitter-pyfold

Folding is a great way to declutter the screen from irrelevant context but overfolding can be equally annoying. Hence, a lua based module for nvim-treesitter, setting some sane folding defaults and provides an optional foldtext.

Installation

Using your favourite package manager

# vim-plug
Plug 'nvim-treesitter-pyfold'

# Packer
require('packer').setup {
    ...
    use 'eddiebergman/nvim-treesitter-pyfold'
    ...
}

Once your package manager has installed the package, in your nvim-treesitter setup, you simply enable the package with:

require('nvim-treesitter.configs').setup {
    ...
    pyfold = {
        enable = true
        custom_foldtext = true -- Sets provided foldtext on window where module is active
    }
    ...
}

If you havn't already, to use treesitter folding, you have to set the following two lines in your .vimrc at some point.

set foldmethod=expr
set foldexpr=nvim_treesitter#fold_expr()

For debuging issues, make these two lines are set using set foldmethod and set foldexpr to verify these are set.

Example

Classes

Classes folding

Functions / Methods

Functions example Multline signature Functions Based on Docs present

Dicts, Lists, Tuples

Dicts, Lists, Tuples folding

TODO

  • Getting multiple imports to fold into one line.
# Code
import one
import two
import three
from x import y
import a as b
from z import ( 
    alpha, beta, phi
)

# Desired
-- imports

The C part of the python tree-sitter parser doesn't want to fold any 'queryable' that only lives on one line, even if you group multiple of them together in query. Please let me know if you know of any workaround for this!