sponsor Vim development Vim logo Vim Book Ad

pyfold : Python Syntax Folding for class/def statements only

 script karma  Rating 21/10, Downloaded by 1741  Comments, bugs, improvements  Vim wiki

created by
David Morris
 
script type
syntax
 
description
This script acts as a syntax-file addon to the standard python.vim syntax file.  When expression folding is used, all classes and functions will be folded automatically.

Each fold ends upon one of two conditions:

1) A line is detected with an indent less than or equal to the previous fold beginning line (that is not in a multi-line string).

2) A line with the same indent as a class or def statement is detected that contains the string "#\s*end\s\+\<\(class\|def\)\>".   (i.e. "    #end class MyClass").

Note that script vimscript #515 provides a similar functionality, but includes marker folding and limited block statement folding.  This script was written to provide class and function folding only, allow "#end \(class\|def\)" lines to end a fold and still be included in the fold, and to increase the speed creating folds in large files.
 
install details
To install, place python.vim in your personal vim syntax directory (e.g. ${HOME}/.vim/syntax).

To use the syntax folding, add either type the command " :set foldmethod=expr " or add the following modeline to the top or bottom of your python file:

# vim6:fdm=expr
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
python.vim 1.0 2003-10-06 6.0 David Morris Initial upload
ip used for rating: 34.204.176.71

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
Vim at Github