Thursday, August 4, 2011

Trying to (begin to) comprehend foldexpr.

After reading :h foldexpr , :h usr_28.txt , and :h folds , the nature
and behaviour of a foldexpr is still only starting to sink in. Some
experiments are helping, to a degree.

On the basis of this example in fold.txt:

»
This will create a fold for all consecutive lines that start with a tab:
:set foldexpr=getline(v:lnum)[0]==\"\\t\"
«

I tried the following, and it folds paragraphs separated by blank
lines, as desired, but also leaves the blank lines between the folds. :-(

:setlocal foldexpr=getline(v:lnum)=~'^.\\+$'
:setl foldtext=getline(v:foldstart)
:setlocal foldmethod=expr

OK, the given example:

:setlocal foldexpr=getline(v:lnum)=~'^\\s*$'&&getline(v:lnum+1)=~'\\S'?'

does the whole thing, but how is it eliding the blank line, so that the
folds aren't double-spaced? The significance of detecting a following
non-blank line, if (as in my test case) there's exactly one blank line
between paragraphs, is far from clear to me.

Uurgh, it's muddy at the bottom of every new learning curve. :-)

Erik

--
Brahma said: Well, after hearing ten thousand explanations, a fool is no
wiser. But an intelligent man needs only two thousand five hundred.
- The Mahabharata

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