Monday, August 1, 2011

Overcoming unintended folding [Was: A mile of dashes added to foldtext]

On 01.08.11 08:29, Benjamin R. Haskell wrote:
> On Mon, 1 Aug 2011, Erik Christiansen wrote:
> >
> >It has also become clear that I'll have to constrain the folding
> >with some "au BufNewFile,BufRead", because .vimrc is only partly
> >displayed, apparently due to the foldtext regex being interpreted
> >as the start of a fold.
>
> Three ways to work around this portion of the problem:
>
> 1. Limit the damage by placing a closing foldmarker in a comment:
>
> e.g.
>
> set foldtext=substitute(getline(v:foldstart),'/\\*\\\|\\*/\\\|{{{\\d\\=','','g') " }}}
>

That is clever and simple to implement. (And revealing of better ways to
think about Vim. :-)

> 2. Replace the three-open-brace portion of the regular expression
> with something equivalent:
>
> e.g.:
>
> Change '{{{' into '[{]{{' " [ed. preventing the fold on this line]: }}}

Chuckle. Yes, the comment is needed.

>
> 3. Use setlocal instead of set to set up foldmethod=marker.
>
> If you set fdm=manual, then folding is manual globally. Then in
> specific filetypes you can enable fdm=marker.
>
> E.g. I use:
>
> " in .vimrc:
> set fdm=manual
> au Filetype php setl fdm=marker

Yes, that was the only one I'd come up with, but had not considered the
need for setlocal. (And just triggering the au on filenames, because my
various info files don't have a different filetype. Also, I'll possibly
want slightly different foldtext on some of the others, when I get to
them.)

Many thanks for the nifty solutions. This is enjoyably educational, as
well as making Vim more powerful here.

Erik

--
Meskimen's Law:
There's never time to do it right, but always time to do it over.

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