5
2
I use vim for all the code I write. My biggest issue is that I cannot find a good Python code folding plugin. I've found two-three popular ones that use indentation but they tend to either fold too little or too much. Ideally, this is what I'd like for it to fold:
- Fold all top level classes.
- Fold all top level functions.
- Fold all class methods
And nothing more. The plugin I am using currently is not bad, but it tends to fold functions within methods. It also gets confused about blocks of code within a class method that have different indentation levels (e.g.: a for loop followed by more code would result in folding of the code after the for loop).
Does anyone know of a plugin that satisfies these requirements or should I just figure out how to write my own?
These are the things I've tried in the past:
- Efficient python folding : Fold python code nicely and toggle with one keystroke - does not fold class methods
- python_fold : Folding expression for python - folds random code blocks
set foldnestmax=2 will work for now, thanks. – ipartola – 2011-07-26T13:36:56.270
Actually, nevermind. For some reason having a function in the middle of a class method still doesn't work. – ipartola – 2011-07-26T13:47:26.043
@ipartola: I amended my answer with more detail about foldnestmax, but it sounds like you need to set a foldexpr. What you really want is to fold all functions and classes (not just top level ones) and nothing else. – idbrii – 2011-07-26T23:27:04.217