In Vim, I'm trying to have all class methods fold automatically when I open a file

0

When I open a PHP file that contains a class, how can I have Vim automatically fold the document up like this?:

enter image description here

Matt Alexander

Posted 2011-11-23T19:30:16.370

Reputation: 749

Answers

2

Perhaps you want to set your 'foldmethod' option to "syntax"?

:set fdm=syntax

If this works as desired, you can put that command in ~/.vim/ftplugin/php.vim (~/vimfiles/ftplugin/php.vim on Windows) to make it automatic when you open a PHP buffer.

Edit: I realized that you may want the class declaration not to be folded by default. To do so, try:

:set foldlevel=1

Heptite

Posted 2011-11-23T19:30:16.370

Reputation: 16 267

3

I think that this combination should work:

set foldmethod=indent
set foldlevelstart=4

You might need to adjust the value of foldlevelstart.

If you only want the functions themselves to be collapsed (and not any blocks within them), you may also want to adjust the value of foldnestmax to be equal to what you set in foldlevelstart.

If you are doing that to have a bird's view of your code you might be intereted by TagList or TagBar.

romainl

Posted 2011-11-23T19:30:16.370

Reputation: 19 227