如何在Vim中获取当前窗口的宽度和高度?
我想根据当前窗口的尺寸创建一个垂直或水平分割的热键,但我不知道要检查哪个变量或方法.
谢谢!
编辑:
这是我现在使用的命令,以防任何人感兴趣.
command! SplitWindow call s:SplitWindow()
function! s:SplitWindow()
let l:height=winheight(0) * 2
let l:width=winwidth(0)
if (l:height > l:width)
:split
else
:vsplit
endif
endfunction
Run Code Online (Sandbox Code Playgroud)
ib.*_*ib. 10
看到winwidth()和winheight()功能.它们都将窗口的数量作为单个参数,并分别返回用该数字标识的窗口的宽度(以字符为单位)和高度(以行为单位).零代表当前窗口.请注意,当没有与给定数字对应的窗口时,返回值等于-1.