Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to obtain split window dimensions in Vim?

Tags:

vim

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
like image 953
suderman Avatar asked Aug 21 '11 02:08

suderman


1 Answers

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.

like image 102
ib. Avatar answered Nov 06 '22 20:11

ib.