Smart window resizing with splits in MacVim

前端 未结 2 818
情深已故
情深已故 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:32

    I realized that my first post modified window height, not width. Here is what I meant:

    Here's a quick solution I came up with, but it's not perfect. The function counts the number of open windows and then sets the window width to original_width * num_windows. The autocommands call the function when Vim starts, and whenever a new window is opened. 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! \="
    endfunction
    
    autocmd VimEnter * call SmartWidth(80)
    autocmd WinEnter * call SmartWidth(80)
    

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

提交回复
热议问题