Resize smart windows with MacVim splitting

I am using the latest MacVim. Is there a way to do this if I open MacVim without a file or with just one file, it sets the window width to n characters? Then, if I do a vertical split, will it expand the window width to 2n characters? The same for 3 vertical splits, but it will stop increasing width after the window has 3n characters. Then if I close these splits, will it resize?

+4
source share
2 answers

It works. Regardless of whether a horizontal split has been made, at any time when vsplit is created or deleted, the window size changes.

let g:auto_resize_width = 40 function! s:AutoResize() let win_width = winwidth(winnr()) if win_width < g:auto_resize_width let &columns += g:auto_resize_width + 1 elseif win_width > g:auto_resize_width let &columns -= g:auto_resize_width + 1 endif wincmd = endfunction augroup AutoResize autocmd! autocmd WinEnter * call <sid>AutoResize() augroup END 

Adjust the width of the window by changing the variable at the top. You probably want to do something like let g:auto_resize_width = &columns to set the width of the original window as the width for resizing.

Everything becomes a little strange if you have so many vsplits that the window becomes as horizontal as possible. I am trying to find a fix and I will send it if I find it.

+4
source

I realized that my first post changed the height of the window, not the width. That's what I meant:

Here is a quick solution that I came up with, but it is not perfect. The function counts the number of open windows, and then sets the window width to original_width * num_windows . Auto-commands invoke a function when Vim starts, and whenever a new window opens. You can change the default window width (80) to suit your needs.

 function! SmartWidth( width ) let num_wins = 0 windo let num_wins+=1 sil exe "set columns=" . num_wins * a:width sil exe "normal! \<cw>=" endfunction autocmd VimEnter * call SmartWidth(80) autocmd WinEnter * call SmartWidth(80) 

This works in the main case, but does not distinguish between horizontal and vertical splits. I do not know how to do that!

0
source

All Articles