Skip to content
README.md 1.81 KiB
Newer Older
Dom Sekotill's avatar
Dom Sekotill committed
Python-Fold
===========

Better Vim folding for python files.


Installing
----------

Use your preferred vim plugin manager:

* [dein](https://github.com/Shougo/dein.vim)
* [vim-plug](https://github.com/junegunn/vim-plug)
* [vundle](https://github.com/VundleVim/Vundle.vim)
* [pathogen](https://github.com/tpope/vim-pathogen)


Usage
-----

The plugin creates folds starting after 'class' and 'def' (including 'async 
def') lines until the last non-blank line before the indent drops to the 
same or a lower level than the 'class' or 'def' line itself.  The fold level 
depends on the nesting of the classes and functions.

Multiline docstrings are also folded.  Their level is ALWAYS below the 
deepest nested class or function (subject to restriction by the 
'foldnestmax' option).  This allows all multiline docstrings to be folded 
without folding anything else.  The easiest way to quickly find the right 
level for this is to type (in normal mode) `zRzm`; this (1) sets the level 
to the highest value in the buffer then (2) drops it down by one.

If classes or functions contain a docstring the first non-blank line of the 
docstring is shown as the fold text, otherwise "[No Docstring]" is shown. 
The fold text for multiline docstrings is always the first non-blank line.


Troubleshooting
---------------

To re-initialise the plugin for a buffer (if fold settings were messed with) 
run the following command while in the buffer:

```
call folds#python#Enable()
```


Known Problems
--------------

1. The entire buffer is scanned when changes are made, which is slow.
2. On starting vim, fold text is not shown.
3. Code (or what looks like code) in multiline strings will be folded.
4. Class/function recognition is simplistic; for instance a line containing 
   just `def:` will cause the subsequent lines to be treated as a function.