No-BS Python code folding
Vim script
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
doc Version 1.1 Mar 16, 2012
ftplugin/python Version 1.1 Mar 16, 2012
LICENSE Version 1.1 Mar 16, 2012
README Version 1.0: Initial upload Sep 9, 2011 Version 1.1 Mar 16, 2012


Because of its reliance on significant whitespace rather than explicit block delimiters, properly folding Python code can be tricky. The Python syntax definition that comes bundled with Vim doesn't contain any fold directives at all, and the simplest workaround is to :set foldmethod=indent, which usually ends up folding a lot more than you really want it to.

There's no shortage of Vim plugins for improved Python folding, but most seem to suffer from cobbled-together algorithms with bizarre, intractable bugs in the corner cases. SimpylFold aims to be exactly what its name suggests: simple, correct folding for Python. It's nothing more than it needs to be: it properly folds class and function/method definitions, and leaves your loops and conditional blocks untouched. There's no BS involved: no screwing around with unrelated options (which several of the other plugins do), no choice of algorithms to scratch your head over (because there's only one that's correct); it just works, simply.


If you're using Pathogen and Git to manage your Vim plugins (highly recommended), you can just

cd ~/.vim
git submodule add bundle/SimpylFold
git submodule init

and you're good to go. Otherwise, clone somewhere else or just grab the tarball, and drop the plugin file into your ~/.vim/ftplugin/python.


No configuration is necessary. However, if you want to enable previewing of your folded classes' and functions' docstrings in the fold text, add the following to your .vimrc:

let g:SimpylFold_docstring_preview = 1


If you find any bugs, please report them and/or submit pull requests on Github! Simple is nice, but simple and correct is much better.

Happy hacking!