Sunday, November 29, 2009

Re: Need help with folding - I'm confused

> 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'"

sounds like a peculiarity of the folding syntax definition.
Alternatively, if you're trying a top-level fold, there might not
actually be a fold there. You can view them more readily by
setting the fold-column width to something non-zero:

:set foldcolumn=3

to view them.

> 1. when I open the file - it is not folded by default

I *think* that the 'foldlevelstart' option controls this,
allowing you to set it to some ridiculously high number like 99.

:help 'foldlevelstart'

Or, if you want (per your later example), you can set it to 1 for
one level of indent.

> 2. I would like to be able to issue a command that folds everything at a
> certain 'depth'

You can manually set it to a certain depth with

:set foldlevel=3

(or whatever level you want), or you can use

zr
zm

to increase/decrease (respectively) the fold level from its
current count (though unfortunately these don't take a prefixed
count of levels to increase/decrease).

:help 'foldlevel'
:help zr
:help zm

> 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

If that works, no need to mess with it :)

> 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)
> }

I think (with "let php_folding=1") setting foldlevel=1 will bring
it to this point. You can map this if you do it regularly

:nnoremap <f4> :set foldlevel=1<cr>

or

:nnoremap <f4> zMzr


-tim


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

No comments:

Post a Comment