Sunday, November 29, 2009

Need help with folding - I'm confused

[disclaimer: I am still a vim novice]

When I've used Visual Studio, UltraEdit, Aptana, Eclipse, etc.. I've noticed 2 things:
1. The ability to fold code is noted in the line number column with a clickable "+" or "-" sign according to the fold status
2. I don't have to tell the IDE where folding is allowed (actually, I can define it with the wordfiles in Ultra Edit)

I've been trying to get code folding to work in Gvim (PHP code) and end up with these results:

Default behavior: manual folding (works as expected)
move cursor to an open '{' and type zf% to fold the code between the braces {}

I don't want to have to do all that 'manual' effort, so I changed .vimrc to this:
set foldmethod=syntax
move cursor to an open '{' and type 'zc': "E490: No fold found"
move cursor to an open '{' and type 'zf': "E350: Cannot create fold with current 'foldmethod'"

So, I made sure that php has folding enabled and added this to .vimrc:
let php_folding = 1
set foldmethod=syntax
when I open the PHP file - *everything* is folded by default now and I have to unfold before I can do anything else...

Here's what I'd like:
1. when I open the file - it is not folded by default
2. I would like to be able to issue a command that folds everything at a certain 'depth'
3. I want vim to remember what lines were folded the last time I was editing the file

I'm pretty sure I'm ok with #3 with these lines in .vimrc:
au BufWinLeave ?* mkview
au BufWinEnter ?* silent loadview

for #2, here's what I'd like to be able to do:

[php code - before folding]
class Foo extends Bar
{
    function __construct()
    {
         //stuff
    }

    function method1($arg1,$arg2)
    {
        //stuff
    }
}


do a folding command to collapse everything that's "1 deep"
class Foo extends Bar
{
+--- 4 lines: function __construct()

+--- 4 lines: function method1($arg1,$arg2)
}


Thanks in advance for pointing me in the right direction :)

Jon

--
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment