I came upon this custom folding for CSS in Vim and inspired by it I was trying to make my own with slightly different result in mind. I had to give up as I couldn't make search patterns work in folding function. No surprise to me as I'm rather a Vim beginner :)
Any help to achieve the following will be much appreciated.
I use empty line(s) for separation for readability. Plus it enables navigation with Vim's } and {.
I put every selector on its own line.
I group declarations into sections, which often are nested.
The sample input is:
/* # Globals
===================================== */
...
/* ## Lists
------------------------------------- */
ol,
ul {
margin-top: 1.6154em; /*21px*/
/* Some other comment */
list-style-position: outside;
}
dl,
dl > some .very.long + selector:not-fitting[on=screen] {
...
I want to:
Fold sections based on their level.
The section level is indicated by a number of
#
, thus in the above example "Globals" should have fold level 1 and "Lists" -- 2. There can be a third level too.The fold text for a section should not contain any
#
.Start a fold for declaration at the first selector.
End a fold at the last empty line following the declaration's closing brace
}
.Display all selectors in the fold text.
In case they don't fit in the window, display those that do and a count of not displayed ones.
I'll illustrate it using the sample provided above.
When using :set foldmethod=marker
and :set foldmarker={,}
the resulting fold is:
ol,
+---- 5 lines: ul -------------------------
dl,
+---- x lines: dl > some .very.long ...----
And I'd like it to be (notice there's no empty line between folds):
+---- ol, ul -------------------------------
+---- dl ---------------------------[1]-----