Resize Window Operator

1 Point

Lucas Groenendaal Lucas Groenendaal

9 years ago

An operator to adjust the height of a window.

" An operator to resize windows. This is nifty because when I
" horizontally split a window, I'll oftentimes use one window for text
" editing and the other to reference a bit of code. Since the
" referenced code is usually a paragraph or other text object I can
" quickly resize that window to encompass what I need to see and
" maximize my screen real estate. TODO: Consider making this also
" adjust horizontal width. There are 3 possibilities I see with this:
" adjust vertical height, adjust horizontal width, or adjust both. I
" wonder how I could reconcile those options or if it's even worth it.
function! ResizeWindowOperator(type, ...)
    " After using an operator, the cursor is put at the
    " start of the operated text, so I think this is okay.
    let start_line = line('.')
    if a:0
        let end_line = line("'>")
    else
        let end_line = line("']")
    endif
    execute "resize ".(end_line-start_line+1)
    normal! zt
endfunction
nnoremap <silent> zS :set operatorfunc=ResizeWindowOperator<CR>g@
vnoremap <silent> zS :<C-u>call ResizeWindowOperator(visualmode(), 1)<CR>