What is the recommended way to use Vim folding for Python code


I am interested in enabling code folding in Vim for Python code. I have noticed multiple ways to do so.

Does anyone have a preferred way to do Python code folding in Vim? I.e,

  • Do you have a particular Vim plugin that you use and like?
  • Do you use manual folding or do you place markers in comments?
  • Any other recommended ways to do code folding for Python in Vim?
7/2/2012 5:29:09 PM

Accepted Answer

Personally I can't convince myself to litter my code with the markers. I've become pretty used to (and efficient) at using indent-folding. Together with my mapping of space bar (see below) to open/close folds and the zR and zM commands, I'm right at home. Perfect for Python!

nnoremap <space> za

vnoremap <space> zf

12/11/2008 7:47:43 PM

I use this syntax file for Python. It sets the folding method to syntax and folds all classes and functions, but nothing else.

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow