本文介绍了在 MacVim 中通过拆分智能调整窗口大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是最新的 MacVim.有什么方法可以让我在没有文件或只有一个文件的情况下打开 MacVim,它将窗口宽度设置为 n 个字符?然后,如果我进行垂直拆分,它会将窗口宽度扩展到 2n 个字符吗?3 个垂直拆分相同,但在窗口为 3n 个字符后它将停止增加宽度.然后,如果我关闭这些拆分,它会缩小吗?

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 vertical split it will expand the window width to 2n characters? Same for 3 vertical splits but it will stop increasing the width after the window is 3n characters. Then if I close those splits it will resize down?

推荐答案

这似乎有效.无论是否进行了水平拆分,每次创建或删除 vsplit 时都会调整窗口大小.

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

通过更改顶部的变量来配置窗口宽度.您可能想要执行类似 let g:auto_resize_width = &columns 的操作,将其设置为使用原始窗口的宽度作为调整大小的宽度.

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.

如果您有太多的 vsplit 以至于窗口水平最大化,事情就会变得有点不稳定.我正在寻找修复方法,如果找到,我会发布.

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.

这篇关于在 MacVim 中通过拆分智能调整窗口大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 08:37