Alex Rivera | Logout

VIM auto resize focused window

Asked 2012-07-24T16:01:00.030
13

I am slowly learning vim and its powerful capabilities. I have a question in regards to splitting windows (mainly horizontal splits). Is there a way to automatically resize the currently selected (focused) window? Let's say, for example, a setting so that the focused window will always take up 70% of the screen.

Using Ctrl-w (number) +/- every time is not really efficient, especially when I am jumping between a few files constantly.

Also it would be cool if there was a way to restrict it to only horizontally splitted windows.

vim
Edit
Report

1 Answer

4

I use these mapping for split screens:

nnoremap <C-j>  <C-w>j
nnoremap <C-k>  <C-w>k
nnoremap <C-h>  <C-w>h
nnoremap <C-l>  <C-w>l
nnoremap c<C-j> :bel sp new<cr>
nnoremap c<C-k> :abo sp new<cr>
nnoremap c<C-h> :lefta vsp new<cr>
nnoremap c<C-l> :rightb vsp new<cr>
nnoremap g<C-j> <C-w>j<C-w>_
nnoremap g<C-k> <C-w>k<C-w>_
nnoremap g<C-h> <C-w>h<C-w>_
nnoremap g<C-l> <C-w>l<C-w>_
nnoremap d<C-j> <C-w>j<C-w>c
nnoremap d<C-k> <C-w>k<C-w>c
nnoremap d<C-h> <C-w>h<C-w>c
nnoremap d<C-l> <C-w>l<C-w>c

This way if you want to jump between splits you can use C-hjkl. If you want to "create" a split you can use cC-hjkl. If you want to maximize a split you can use gC-hjkl. And if you want to delete a split you can use dC-hjkl.

If you want specifically 70% instead of maximized that you could use

nnoremap g<C-j> <C-w>j:let &winheight = &lines * 7 / 10<cr>

for example.

answered 2012-07-24T16:30:53.563

Your Answer