Last Updated: February 25, 2016
·
2.367K
· gahtune

Vim window resizing ala tmux

Resizing window in vim is painful. You need to repeatly press "Ctrl W" and "+" (or "-", ">", "<").
TinyKeymap is an awesome plugin that will help you factorize the "Ctrl W".
Just add some mappings to ease resizing and moving around the splits:

call tinykeymap#Load('windows')

call tinykeymap#Map('windows', '<C-right>', 'wincmd >')
call tinykeymap#Map('windows', '<C-left>', 'wincmd <')
call tinykeymap#Map('windows', '<C-up>', 'wincmd +')
call tinykeymap#Map('windows', '<C-k>', 'wincmd +')
call tinykeymap#Map('windows', '<C-j>', 'wincmd -')
call tinykeymap#Map('windows', '<C-h>', 'wincmd <')
call tinykeymap#Map('windows', '<C-l>', 'wincmd >')

call tinykeymap#Map('windows', 'l', 'wincmd l')
call tinykeymap#Map('windows', 'h', 'wincmd h')
call tinykeymap#Map('windows', 'j', 'wincmd j')
call tinykeymap#Map('windows', 'k', 'wincmd k')
call tinykeymap#Map('windows', 'q', 'wincmd q')

Explanation

When you press Ctrl W, vim enter in a "tinymode" where is defined special mappings like for example Ctrl left to decrease the horizontal size.
You can press ESC to go out of the tinymap.

2 Responses
Add your response

I don't think TinyKeymap is necessary to easily resize windows and move around the splits. I use simple mappings:

" Resizing windows
nnoremap <C-up> <C-W>+
nnoremap <C-down> <C-W>-
nnoremap <C-left> <C-W><
nnoremap <C-right> <C-W>>

" Moving around splits
nnoremap <C-J> <C-W>j
nnoremap <C-K> <C-W>k
nnoremap <C-L> <C-W>l
nnoremap <C-H> <C-W>h

" Closing windows
nnoremap <C-C>l <C-W>l:q<CR>
nnoremap <C-C>h <C-W>h:q<CR>
nnoremap <C-C>j <C-W>j:q<CR>
nnoremap <C-C>k <C-W>k:q<CR>
over 1 year ago ·

You are right, but your mapping override the move one word (but if you are a real vimer you will tell me that "b", "w", or "e" do the same and you will be right!)

I'm myself not really convince, by the tinymap key solution because it introduce a small lag time. But that's the nearer to tmux way of doing that I found.

over 1 year ago ·