There is a (moderately complicated) way to make an autocommand that only runs when windows are created, but I want to have one for when they are removed as well.
The reason is that whenever a window is created or removed I'd like to run a function I wrote which calculates window heights and re-assigns them into the open windows.
It's mainly about efficient allocation of screen space (tiling). When you remove a window, or add one, any small files may get stretched out into the average height and then it is a pain to shrink them down again.
I don't know that there's a way to embed on this site, so here is gfy link.
https://gfycat.com/UnrulyLikelyDrever
The 9 line file at the bottom ends up taking up half the space once the middle window is closed.
My routine automates it a bit so it works sort of like a tiling window system, but since vimscript is missing some API that would make things nicer it is somewhat slow to run (as I have to use wincmd j/k
to move around a bunch inside the function). Therefore I'd like to trigger this only when necessary, which means only when creating or removing entire windows (not upon entry to or exiting focus from them).
Indeed the linked solution for a window open autocommand doesn't even work properly, as I'd really need to have it run after the buffer has loaded (to know the number of lines in the buffer), but I am willing to accept a half-baked solution at this stage.
So the point is I need some autocommands that effectively let me find out when window reflow has occurred. Since there's clearly no WindowReflowed autocommand for this I am looking for some hacks.