Read'n'Code - Flaviu Simihaian's Blog

Resizing Vim Window Splits Like a Boss

If you’re using Vim as your text editor (if you’re not, these videos will convince you), you’re probably using window splits.

If you’re using window splits, you probably wished you had a quick way to resize them.

I recently watched Gary Bernhardt’s video on VIM File Navigation, and got inspired to research this problem.

So, set the following in your ~/.vimrc:

set winheight=30
set winminheight=5

This will make sure all splits will be at least 5 lines (which is enough for reference), and the current window will be 30 lines. As you navigate through the windows, the current one will become 30 lines.

You can increase or decrease the size of a window by one line with Ctrl-w + - and Ctrl-w + +.

That probably makes no sense. So you should use + and - to increase or decrease windows by a sane amount:

nnoremap <silent> + :exe "resize " . (winheight(0) * 3/2)<CR>
nnoremap <silent> - :exe "resize " . (winheight(0) * 2/3)<CR>

As for navigation, I’m using these mappings to move between splits with Ctrl-w + - and Ctrl-w + *+:

nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l

Also, if you want to make all windows equal, use Ctrl-w + =

Check this out for similar nuggets.


Fork Flaviu on GitHub