其想法是做一些类似于黄金比率 ( vim插件)所做的事情。但是,我不想将大小调整到“黄金比率”,而是要为未选定的窗口设置特定的大小。
例如:
# Window 1 selected
----------------------
| | | | |
| | | | |
| 1 | 2 | 3 | 4 |
| | | | |
| | | | |
----------------------
# Window 3 selected
----------------------
| | | | |
| | | | |
| 1 | 2 | 3 | 4 |
| | | | |
| | | | |
----------------------以下是我到目前为止所写的(只是一个WIP):
function g:ResizeWindow()
let tabs = gettabinfo()
let current_tabnr = tabpagenr()
let current_window = win_getid()
let tab = filter(tabs, 'v:val.tabnr == current_tabnr')[0]
for window in tab.windows
if window != current_window
call win_gotoid(window)
exe 'vertical resize' 20
endif
endfor
call win_gotoid(current_window)
let current_window_size = &columns - ((len(tab.windows) - 1) * 20)
exe 'vertical resize' current_window_size
endfunction
autocmd WinNew,WinEnter * :call g:ResizeWindow()要进行测试,您可以打开一个缓冲区,并只需:vsp几次。然后,当您导航窗口时,它在大多数情况下似乎都能工作,但偶尔其中一个窗口会以一种不一致的方式崩溃。比其他的要小得多。这通常发生在我从左到右导航时.从右到左的后背。
对这件事有什么不好的地方,以及如何解决?
发布于 2020-04-16 22:10:06
超级有趣的功能!
下面是一个有用的版本:
function g:ResizeWindow()
let tabs = gettabinfo()
let current_tabnr = tabpagenr()
let current_window = win_getid()
let tab = filter(tabs, 'v:val.tabnr == current_tabnr')[0]
let small_size = 5
for window in tab.windows
if window == current_window
let size = &columns - ((len(tab.windows) - 1) * small_size) - (len(tab.windows) - 1)
else
let size = small_size
endif
noautocmd call win_gotoid(window)
exe 'noautocmd vertical resize ' . size
endfor
call win_gotoid(current_window)
endfunction
set winwidth=1
set winminwidth=1
autocmd WinNew,WinEnter * :call g:ResizeWindow()解释
我对您的初始WIP做了一些更改,下面是您的代码遇到的主要问题:
win_gotoid的调用触发了autocmd。所以这搞砸了所有的尺寸minwinwidth)和默认窗口大小(winwidth)正在影响应用的大小。免责声明
如果在一个窗口上有一个水平分割,此函数就会中断!
https://stackoverflow.com/questions/61243238
复制相似问题