Window Resizing - Split Resizing

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Window Resizing - Split Resizing

Dominic Evans
Once I have multiple splits open at the default application window
size (80x25) I often find myself needing to maximise the windows.
However I have never quite understood how Vim decides to resize the
splits. It generally seems to just increase the size of one of them
dramatically - leaving the others all exactly the size they were
before.

Is it possible via some .vimrc trickery to make all the splits
increase in size in respect to their ratio to each other.

i.e. if one split is 1/3 of the 80 column width and the other is the
2/3. Then when I increase the overall window width to 120 I'd like the
ratio of the split sizes to remain the same so they both get more
space from the increase.

Many thanks for any help,
Dominic
Reply | Threaded
Open this post in threaded view
|

Re: Window Resizing - Split Resizing

A.J.Mechelynck
----- Original Message -----
From: "Dominic Evans" <[hidden email]>
To: <[hidden email]>
Sent: Monday, September 05, 2005 9:58 AM
Subject: Window Resizing - Split Resizing


> Once I have multiple splits open at the default application window
> size (80x25) I often find myself needing to maximise the windows.
> However I have never quite understood how Vim decides to resize the
> splits. It generally seems to just increase the size of one of them
> dramatically - leaving the others all exactly the size they were
> before.
>
> Is it possible via some .vimrc trickery to make all the splits
> increase in size in respect to their ratio to each other.
>
> i.e. if one split is 1/3 of the 80 column width and the other is the
> 2/3. Then when I increase the overall window width to 120 I'd like the
> ratio of the split sizes to remain the same so they both get more
> space from the increase.
>
> Many thanks for any help,
> Dominic

In this particular case I don't know how to achieve what you're asking for.
However, if all splits are the same size, then 'equalalways' and
'eadirection' (q.v.) will keep them the same size when windows are opened or
closed; and the Normal-mode Ctrl-W = command will make them the same size if
for some reason they aren't (but see also 'winheight' and 'winwidth').

You can always change the ratio of split window sizes by dragging the
vertical separation (for vertical splits) and/or the separating status line
(for horizontal splits) with the mouse -- provided of course that your
current Vim sees mouse actions.


Best regards,
Tony.


Reply | Threaded
Open this post in threaded view
|

RE: Window Resizing - Split Resizing

Keith W. Roberts
 

> -----Original Message-----
> From: Tony Mechelynck [mailto:[hidden email]]
> Sent: Monday, September 05, 2005 2:43 AM
> To: [hidden email]; [hidden email]
> Subject: Re: Window Resizing - Split Resizing
>
> ----- Original Message -----
> From: "Dominic Evans" <[hidden email]>
> To: <[hidden email]>
> Sent: Monday, September 05, 2005 9:58 AM
> Subject: Window Resizing - Split Resizing
>
>
> > Once I have multiple splits open at the default application window
> > size (80x25) I often find myself needing to maximise the windows.
> > However I have never quite understood how Vim decides to resize the
> > splits. It generally seems to just increase the size of one of them
> > dramatically - leaving the others all exactly the size they were
> > before.
> >
> > Is it possible via some .vimrc trickery to make all the splits
> > increase in size in respect to their ratio to each other.
> >
> > i.e. if one split is 1/3 of the 80 column width and the other is the
> > 2/3. Then when I increase the overall window width to 120
> I'd like the
> > ratio of the split sizes to remain the same so they both get more
> > space from the increase.
> >
> > Many thanks for any help,
> > Dominic
>
> In this particular case I don't know how to achieve what
> you're asking for.
> However, if all splits are the same size, then 'equalalways' and
> 'eadirection' (q.v.) will keep them the same size when
> windows are opened or
> closed; and the Normal-mode Ctrl-W = command will make them
> the same size if
> for some reason they aren't (but see also 'winheight' and 'winwidth').
>
> You can always change the ratio of split window sizes by dragging the
> vertical separation (for vertical splits) and/or the
> separating status line
> (for horizontal splits) with the mouse -- provided of course
> that your
> current Vim sees mouse actions.
 
I think the idea (when 'ea' is not set) is to give the extra real estate to
the current window, which is most likely what the user wants.  I doubt that
behavior will change.

OTOH, you could map the "maximize" key sequence to call your own function,
which could:
- save current winnr()
- do 99^Wh to go all the way left
- start a list of window nos.
- for each window, save %width (&wiw*100/&co), using ^Wl to traverse right
- skip "current" window, so that rounding error in %width gives any extra to
it
- when you can't go any further right, return to saved winnr() and maximize,
then set each window in list to correct % of *new* &columns (:let &wiw = &co
* %width / 100)

A bit of work, but it'll get you where you want.

-Keith


Reply | Threaded
Open this post in threaded view
|

Re: Window Resizing - Split Resizing

Dominic Evans
At that rate it'd probably be easier for me to write a patch against
the source that provides the option and try and get Bram to include
it.

Probably be less work in .c and more likely to work :)

Cheers,
Dom

On 06/09/05, Keith W. Roberts <[hidden email]> wrote:

>
>
> > -----Original Message-----
> > From: Tony Mechelynck [mailto:[hidden email]]
> > Sent: Monday, September 05, 2005 2:43 AM
> > To: [hidden email]; [hidden email]
> > Subject: Re: Window Resizing - Split Resizing
> >
> > ----- Original Message -----
> > From: "Dominic Evans" <[hidden email]>
> > To: <[hidden email]>
> > Sent: Monday, September 05, 2005 9:58 AM
> > Subject: Window Resizing - Split Resizing
> >
> >
> > > Once I have multiple splits open at the default application window
> > > size (80x25) I often find myself needing to maximise the windows.
> > > However I have never quite understood how Vim decides to resize the
> > > splits. It generally seems to just increase the size of one of them
> > > dramatically - leaving the others all exactly the size they were
> > > before.
> > >
> > > Is it possible via some .vimrc trickery to make all the splits
> > > increase in size in respect to their ratio to each other.
> > >
> > > i.e. if one split is 1/3 of the 80 column width and the other is the
> > > 2/3. Then when I increase the overall window width to 120
> > I'd like the
> > > ratio of the split sizes to remain the same so they both get more
> > > space from the increase.
> > >
> > > Many thanks for any help,
> > > Dominic
> >
> > In this particular case I don't know how to achieve what
> > you're asking for.
> > However, if all splits are the same size, then 'equalalways' and
> > 'eadirection' (q.v.) will keep them the same size when
> > windows are opened or
> > closed; and the Normal-mode Ctrl-W = command will make them
> > the same size if
> > for some reason they aren't (but see also 'winheight' and 'winwidth').
> >
> > You can always change the ratio of split window sizes by dragging the
> > vertical separation (for vertical splits) and/or the
> > separating status line
> > (for horizontal splits) with the mouse -- provided of course
> > that your
> > current Vim sees mouse actions.
>
> I think the idea (when 'ea' is not set) is to give the extra real estate to
> the current window, which is most likely what the user wants.  I doubt that
> behavior will change.
>
> OTOH, you could map the "maximize" key sequence to call your own function,
> which could:
> - save current winnr()
> - do 99^Wh to go all the way left
> - start a list of window nos.
> - for each window, save %width (&wiw*100/&co), using ^Wl to traverse right
> - skip "current" window, so that rounding error in %width gives any extra to
> it
> - when you can't go any further right, return to saved winnr() and maximize,
> then set each window in list to correct % of *new* &columns (:let &wiw = &co
> * %width / 100)
>
> A bit of work, but it'll get you where you want.
>
> -Keith
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Window Resizing - Split Resizing

A.J.Mechelynck
In reply to this post by Keith W. Roberts
----- Original Message -----
From: "Keith W. Roberts" <[hidden email]>
To: "'Tony Mechelynck'" <[hidden email]>;
<[hidden email]>; <[hidden email]>
Sent: Tuesday, September 06, 2005 7:27 PM
Subject: RE: Window Resizing - Split Resizing


>
>
>> -----Original Message-----
>> From: Tony Mechelynck [mailto:[hidden email]]
>> Sent: Monday, September 05, 2005 2:43 AM
>> To: [hidden email]; [hidden email]
>> Subject: Re: Window Resizing - Split Resizing
>>
>> ----- Original Message -----
>> From: "Dominic Evans" <[hidden email]>
>> To: <[hidden email]>
>> Sent: Monday, September 05, 2005 9:58 AM
>> Subject: Window Resizing - Split Resizing
>>
>>
>> > Once I have multiple splits open at the default application window
>> > size (80x25) I often find myself needing to maximise the windows.
>> > However I have never quite understood how Vim decides to resize the
>> > splits. It generally seems to just increase the size of one of them
>> > dramatically - leaving the others all exactly the size they were
>> > before.
>> >
>> > Is it possible via some .vimrc trickery to make all the splits
>> > increase in size in respect to their ratio to each other.
>> >
>> > i.e. if one split is 1/3 of the 80 column width and the other is the
>> > 2/3. Then when I increase the overall window width to 120
>> I'd like the
>> > ratio of the split sizes to remain the same so they both get more
>> > space from the increase.
>> >
>> > Many thanks for any help,
>> > Dominic
>>
>> In this particular case I don't know how to achieve what
>> you're asking for.
>> However, if all splits are the same size, then 'equalalways' and
>> 'eadirection' (q.v.) will keep them the same size when
>> windows are opened or
>> closed; and the Normal-mode Ctrl-W = command will make them
>> the same size if
>> for some reason they aren't (but see also 'winheight' and 'winwidth').
>>
>> You can always change the ratio of split window sizes by dragging the
>> vertical separation (for vertical splits) and/or the
>> separating status line
>> (for horizontal splits) with the mouse -- provided of course
>> that your
>> current Vim sees mouse actions.
>
> I think the idea (when 'ea' is not set) is to give the extra real estate
> to
> the current window, which is most likely what the user wants.  I doubt
> that
> behavior will change.
>
> OTOH, you could map the "maximize" key sequence to call your own function,
> which could:
> - save current winnr()
> - do 99^Wh to go all the way left

or 1^Ww to go to the first window

> - start a list of window nos.
> - for each window, save %width (&wiw*100/&co), using ^Wl to traverse right

&wiw won't work, it's a global "desired minimum". Use winwidth(0) and
possibly winheight(0) to do the same when resizing top-to-bottom.

or ^Ww to traverse all (round-robin). You can also use ^Ww repeatedly from
where you are [after saving winnr()] and stop when you're back at the same
number. To reduce rounding errors I recommend saving &columns (once) and
winwidth(0) (for each window). Possibly also &lines and winheight(0).

*NOTE* All code snippets below are untested

    let curwin = winnr()
    let old_columns = &columns
    let old_llines = &lines
    while 1
        let old_width_{winnr()} = winwidth(0)
        let old_height_{winnr()} = winheight(0)
        wincmd w
        if winnr() == curwin
            break
        endif
    endwhile

> - skip "current" window, so that rounding error in %width gives any extra
> to
> it
> - when you can't go any further right, return to saved winnr() and
> maximize,
> then set each window in list to correct % of *new* &columns (:let &wiw =
> &co
> * %width / 100)

    " (example) maximize both ways
    set lines=99999 columns=99999

    wincmd w
    while winnr() != curwin
        let old_width = old_width_{winnr()}
        let old_height = old_height_{winnr()}
        let new_width = (old_width * &columns) / old_columns
        let new_height = (old_height * &lines) / old_lines
        if new_width == old_width
            " do nothing
        elseif new_width > old_width
            exe "wincmd +" (new_width - old_width)
        else
            exe "wincmd -" (old_width - new_width)
        endif
        if new_height == old_height
            " do nothing
        elseif new_height > old_height
            exe "wincmd +" (new_height - old_height)
        else
            exe "wincmd -" (old_height - new_height)
        endif
    endwhile

Multiply first and divide afterwards to minimize rounding errors.


>
> A bit of work, but it'll get you where you want.
>
> -Keith


Reply | Threaded
Open this post in threaded view
|

RE: Window Resizing - Split Resizing

Keith W. Roberts
 

> -----Original Message-----
> From: Tony Mechelynck [mailto:[hidden email]]
> Sent: Tuesday, September 06, 2005 1:05 PM
> To: Keith W. Roberts; [hidden email]; [hidden email]
> Subject: Re: Window Resizing - Split Resizing
>
> ----- Original Message -----
> From: "Keith W. Roberts" <[hidden email]>
> To: "'Tony Mechelynck'" <[hidden email]>;
> <[hidden email]>; <[hidden email]>
> Sent: Tuesday, September 06, 2005 7:27 PM
> Subject: RE: Window Resizing - Split Resizing
>
>
> >
> >
> >> -----Original Message-----
> >> From: Tony Mechelynck [mailto:[hidden email]]
> >> Sent: Monday, September 05, 2005 2:43 AM
> >> To: [hidden email]; [hidden email]
> >> Subject: Re: Window Resizing - Split Resizing
> >>
> >> ----- Original Message -----
> >> From: "Dominic Evans" <[hidden email]>
> >> To: <[hidden email]>
> >> Sent: Monday, September 05, 2005 9:58 AM
> >> Subject: Window Resizing - Split Resizing
> >>
> >>
> >> > Once I have multiple splits open at the default
> application window
> >> > size (80x25) I often find myself needing to maximise the windows.
> >> > However I have never quite understood how Vim decides to
> resize the
> >> > splits. It generally seems to just increase the size of
> one of them
> >> > dramatically - leaving the others all exactly the size they were
> >> > before.
> >> >
> >> > Is it possible via some .vimrc trickery to make all the splits
> >> > increase in size in respect to their ratio to each other.
> >> >
> >> > i.e. if one split is 1/3 of the 80 column width and the
> other is the
> >> > 2/3. Then when I increase the overall window width to 120
> >> I'd like the
> >> > ratio of the split sizes to remain the same so they both get more
> >> > space from the increase.
> >> >
> >> > Many thanks for any help,
> >> > Dominic
> >>
> >> In this particular case I don't know how to achieve what
> >> you're asking for.
> >> However, if all splits are the same size, then 'equalalways' and
> >> 'eadirection' (q.v.) will keep them the same size when
> >> windows are opened or
> >> closed; and the Normal-mode Ctrl-W = command will make them
> >> the same size if
> >> for some reason they aren't (but see also 'winheight' and
> 'winwidth').
> >>
> >> You can always change the ratio of split window sizes by
> dragging the
> >> vertical separation (for vertical splits) and/or the
> >> separating status line
> >> (for horizontal splits) with the mouse -- provided of course
> >> that your
> >> current Vim sees mouse actions.
> >
> > I think the idea (when 'ea' is not set) is to give the
> extra real estate
> > to
> > the current window, which is most likely what the user
> wants.  I doubt
> > that
> > behavior will change.
> >
> > OTOH, you could map the "maximize" key sequence to call
> your own function,
> > which could:
> > - save current winnr()
> > - do 99^Wh to go all the way left
>
> or 1^Ww to go to the first window

Not what the OP wants.  The leftmost vertically split window isn't
necessarily the 1st window; the user may have several sets of vertical
splits in different horizontal tiers.

> > - start a list of window nos.
> > - for each window, save %width (&wiw*100/&co), using ^Wl to
> traverse right
>
> &wiw won't work, it's a global "desired minimum". Use winwidth(0) and
> possibly winheight(0) to do the same when resizing top-to-bottom.

Good point; thanks!  I wasn't thinking clearly. :)  For horizontal splits I
would have used winheight() w/o thought, but right now I only use vsp for
diffs ... and didn't have the time to flesh it out, which would've shown the
error.

-Keith



Reply | Threaded
Open this post in threaded view
|

Re: Window Resizing - Split Resizing

A.J.Mechelynck
----- Original Message -----
From: "Keith W. Roberts" <[hidden email]>
To: "'Tony Mechelynck'" <[hidden email]>;
<[hidden email]>; <[hidden email]>
Sent: Wednesday, September 07, 2005 12:44 AM
Subject: RE: Window Resizing - Split Resizing


>
>
>> -----Original Message-----
>> From: Tony Mechelynck [mailto:[hidden email]]
>> Sent: Tuesday, September 06, 2005 1:05 PM
>> To: Keith W. Roberts; [hidden email]; [hidden email]
>> Subject: Re: Window Resizing - Split Resizing
[...]
>> or 1^Ww to go to the first window
>
> Not what the OP wants.  The leftmost vertically split window isn't
> necessarily the 1st window; the user may have several sets of vertical
> splits in different horizontal tiers.
[...]

Well, the way I read it, he wants all windows to be resized proportionally.
See the snippets of code I provided to traverse all windows round-robin from
the current one. Alternately, all windows could be accessed by number from 1
to winnr("$") using winwidth(i) and not changing the current window.


Best regards,
Tony.


Reply | Threaded
Open this post in threaded view
|

RE: Window Resizing - Split Resizing

Keith W. Roberts
 

> -----Original Message-----
> From: Tony Mechelynck [mailto:[hidden email]]
> Sent: Tuesday, September 06, 2005 4:10 PM
> To: Keith W. Roberts; [hidden email]; [hidden email]
> Subject: Re: Window Resizing - Split Resizing
>
> ----- Original Message -----
> From: "Keith W. Roberts" <[hidden email]>
> To: "'Tony Mechelynck'" <[hidden email]>;
> <[hidden email]>; <[hidden email]>
> Sent: Wednesday, September 07, 2005 12:44 AM
> Subject: RE: Window Resizing - Split Resizing
>
>
> >
> >
> >> -----Original Message-----
> >> From: Tony Mechelynck [mailto:[hidden email]]
> >> Sent: Tuesday, September 06, 2005 1:05 PM
> >> To: Keith W. Roberts; [hidden email]; [hidden email]
> >> Subject: Re: Window Resizing - Split Resizing
> [...]
> >> or 1^Ww to go to the first window
> >
> > Not what the OP wants.  The leftmost vertically split window isn't
> > necessarily the 1st window; the user may have several sets
> of vertical
> > splits in different horizontal tiers.
> [...]
>
> Well, the way I read it, he wants all windows to be resized
> proportionally.
> See the snippets of code I provided to traverse all windows
> round-robin from
> the current one. Alternately, all windows could be accessed
> by number from 1
> to winnr("$") using winwidth(i) and not changing the current window.
>
>
> Best regards,
> Tony.

Ah, yes.  I *had* actually thought of that briefly, but by the time I got
what I had written down, I'd forgotten it again. :)  Boy, I wish I'd
actually done the drugs that might have been responsible for all those
"lost" brain cells ... :) Just kidding.

-Keith