How do I do get the width and height of the current window in Vim?
I want to create a single hotkey to split either vertically or horizontally based on the current window's dimensions, but I don't know what variable or method to check.
Thanks!
Edit:
Here's the command I'm now using in case anyone is interested.
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
See winwidth()
and winheight()
functions. Both of them take the number of
a window as a single argument, and return, respectively, width (in characters)
and height (in lines) of the window identified with that number. Zero stands
for the current window. Note that return value equals to -1 when there is no
window corresponding to the given number.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With