Here is my use case:
I have lots of code which because of style enforcement we write newlines after and before each open and close brace (respectively).
Example:
function func(args) { statement 1; statement 2; if (condition) { statement 3; } } While this is nice and easy to read, I do consider this to be a expletive-worthy waste of space, but my teammates do not agree with me. Basically this is how we're checking in our code and that's that.
I was thinking that maybe I can use Vim features to help me save screen real-estate, while still allowing me to write the code in the verbose way. I don't mind typing it out, I just want more efficient use of space. I figured maybe I can have Vim auto-collapse the gratuitous empty lines.
I am finding it somewhat challenging to set this up using syntax rules because whatever I write seems to conflict with existing syntax rules, but what I decided to do as a first attempt was to write these rules which will not collide:
syntax match aaaaaaaaa "\vabcd" conceal cchar=A syntax match bbbbbbbbb "\vef\ngh" conceal cchar=B The second rule here is close to what I want, which for the open bracket case is something like /\v\{(\n\s*){2,}: match an open-bracket with any number greater than or equal to 2 of a newline followed by only whitespace.
What happens inside of vim however is the following:
If I type
abcdin a line, it gets concealed toAas expected.If I type
efon one line andghon the next, BOTH lines become concealed withB.
I was really really hoping the two lines ef\ngh would have been concealed into a single line so that I can save some vertical buffer space this way.
But I see now that it's probably a Vim implementation detail problem. Collapsing lines is a problem for code folding to solve, probably just out of scope as far as conceal is concerned.
So I wonder if there is still some way to do what I want to do. Maybe using fold markers somehow? The problem is that I need to fold only the empty whitespace.

gityou might even be able to use hooks to make the changes apply transparently.:h fold-exprand:h 'fdm'