Tuesday, November 20, 2012

Re: Auto folding ONLY on blocks starting from column 1

On Tuesday, November 20, 2012 1:48:55 PM UTC-6, Philip Rhoades wrote:
>
> On Nov 20, 2012; 8:01am, Ben Fritz wrote:
> > On Monday, November 19, 2012 2:31:49 PM UTC-6, Philip Rhoades wrote:
>
> >> I have been playing around with folding options in .vimrc but can't
> >>
> >> work out how to do what I want which is:
> >>
> >> - Fold all blocks between the first line of the block and the "end"
> >>
> >> line but ONLY only for those blocks whose first line starts at
> >> column 1.
> >>
> >> Is this possible?
> >>
> >
> > What do you mean by "block"? How do you know where it starts and
> > ends? This should be fairly easy to do with a foldexpr.
>
>
> Sorry, silly of me - I should have said when editing Ruby blocks eg:
>
> if (..)
> .
> .
> end
>
> or
>
> tst = proc{ tarr
> .
> .
> }
>
>

First, it looks like this will fold more than you want, but just in case it
is acceptable to you, have you tried the Ruby syntax folding?

See :help ruby.vim for the options on Ruby syntax. Near the end are the
folding options ruby_fold and ruby_no_comment_fold.

If all you want is the specific blocks you mention, and if you're not too
worried about being precisely correct, you could make a foldexpr which
depends on not only the beginning of the match but also the end being in the
first column. Something like:

fun! MyFoldBlocks()
if getline(v:lnum)=~'\v^(if|(\S&.*\{)|SomeOtherBlockBeginning)'
return ">1"
elseif getline(v:lnum)=~'\v^(end|\}|SomeOtherBlockEnding)'
return "<1"
else
return "="
endif
endfun
setl foldexpr=MyFoldBlocks() fdm=expr

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment