开发者

How to obtain split window dimensions in 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=winw开发者_JS百科idth(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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜