Smart window resizing with splits in MacVim

前端 未结 2 820
情深已故
情深已故 2021-01-19 17:50

I\'m using the latest MacVim. Is there any way to have it so if I open MacVim without a file or with only one file, it sets the window width to n characters? Then if I do a

2条回答
  •  悲哀的现实
    2021-01-19 18:45

    This appears to work. Whether or not a horizontal split has been done, any time a vsplit is created or deleted the window is resized.

    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 AutoResize()
    augroup END
    

    Configure the window width by changing the variable at the top. You probably want to do something like let g:auto_resize_width = &columns to set it to use the width of the original window as the width to resize by.

    Things get a little wonky if you have so many vsplits that the window becomes maximized horizontally. I'm trying to find a fix and I'll post it if I find one.

提交回复
热议问题