For the rectangle minimization problem: your problem seems to differ from the one discussed on StackOverflow in that the SO thread discusses partitioning into non-overlapping rectangles, while your Vim project allows overlap.
I wouldn't be surprised if your problem turns out to be much easier to solve optimally.