Rey
Rey

Reputation: 3767

How to resize split windows in Vim proportionally?

Ok so first off, this is NOT the answer I'm looking for:

autocmd VimResized * :wincmd =

Let me explain: Let's assume I have 2 vertically split windows, one at 30% size and one at 70% size. When I resize my window, I want that percentage to stay the same. Without this command, the split on the right slowly collapses so that you eventually can't see anything in the window. With the command above, once you start resizing the window, the window sizes immediately change to 50%/50%.

I work with a lot of splits (vertical and horizontal) and I don't want the command above to just make everything equal, but at the same time I do want them to resize, just PROPORTIONALLY to the window... I want the percentage height/width of all splits in the window to stay the same when the window is resized. Ideas?

Upvotes: 7

Views: 4964

Answers (3)

Ingo Karkat
Ingo Karkat

Reputation: 172520

I've attempted to implement this in my ProportionalResize plugin, following basically the approach outlined in romainl's answer. You can wrap your resize commands in a :ProportionalResize wrapper; the plugin also hooks into various events to allow automatic adaptation when the Vim window is resized e.g. with the mouse.

Upvotes: 3

romainl
romainl

Reputation: 196476

You could create a function that logs window sizes and bind them to a bunch of events like WinEnter/WinLeave and another one bound to VimResized that uses those values to resize the windows.

This doesn't sound like a trivial task.

Or even like a good idea.

Upvotes: 2

Kent
Kent

Reputation: 195039

if you are asking a "vim - official" way to do that, answer is NO. (Vim 7.3)

to prove it:

open vim, type :h todo<Enter>then type /proportionally[Enter] you will see:

-   When resizing the whole Vim window, the windows inside should be resized
    proportionally (Webb).

so it is in vim's todo list. In this window type gg, you can see the leading minus "-" means Priority classification:

-   unclassified

If you want to do it, you could write a function by yourself, on VimResized event, resize all windows based on your logic.

Upvotes: 3

Related Questions