Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
up vote 1 down vote accepted

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
share|improve this answer

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.

share|improve this answer
Thanks for the edit, Jacob. – romainl Nov 24 '11 at 7:32

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.