7

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?

Rey
  • 3,639
  • 5
  • 33
  • 40

3 Answers3

3

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.

Kent
  • 189,393
  • 32
  • 233
  • 301
  • No I'm not asking for an official way to do it. Just a way to do it. And I'm not good enough to write the function myself. – Rey Feb 01 '13 at 15:52
3

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.

Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
  • You should mention somewhere in the plugin's documentation that it relies on inkarkat/vim-ingo-library (for ingo#msg#errormsg) – Von Jul 07 '17 at 00:29
  • 1
    @Von: It does - right on the plugin page, and in the help file: _- Requires the ingo-library.vim plugin (vimscript #4433), version 1.000 or higher._ – Ingo Karkat Jul 07 '17 at 08:47
  • Ah, my bad. Sorry. – Von Jul 08 '17 at 21:34
2

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.

romainl
  • 186,200
  • 21
  • 280
  • 313
  • upvote - although, personally, doesn't sound like a bad idea to me. If one were to do this, one would need to store window width/height like `line('w$') - line('w0')` and `winwidth(...)`. – dsummersl Feb 03 '13 at 16:28
  • Well… what to store is rather obvious. How to store it and when is not that obvious to me. The whole thing sounds a bit fragile IMO. Writing a patch that adds a `VimResizedPre` event would probably be quicker. – romainl Feb 03 '13 at 17:04