Common Way of Resizing Windows/Panes in Vim and Tmux

Published .

Artwork for article Common Way of Resizing Windows/Panes in Vim and Tmux

It’s not often, but once in a while I want to resize a window in Vim or a pane in Tmux. And every time πŸ˜’, I’m thinking that I should rebind some keys to make the two programs more similar.

Vim

So in Vim I use the default bindings for resizing buffers. But I’ve tweaked them a bit 😏. The only thing I’ve done is to rebind the keys in whatever mode, so just noremap, to increase and decrease by 5 instead of the default 1.

noremap <C-w>+ :resize +5<CR>
noremap <C-w>- :resize -5<CR>
noremap <C-w>< :vertical:resize -5<CR>
noremap <C-w>> :vertical:resize +5<CR>

More info in Vim help system at :h window-resize.

Tmux

In Tmux I bind the same keys used in Vim (now with Tmux prefix obviously, I use Ctrl+A like most others). Here I change the value by 10 instead of 5. Only reason for this is that it feels right. I think the system are in columns and rows or something, but that doesn’t really matter.

bind-key -r β€˜+’ resize-pane -U 10
bind-key -r β€˜-’ resize-pane -D 10
bind-key -r β€˜<’ resize-pane -L 10
bind-key -r β€˜>’ resize-pane -R 10

The -r flag passed into the binding makes it repeatable. So when you press your prefix, you have a certain time to hammer > for example to make the pane increase to the right. The time you got depends on your repeat-time option which defaults to 500 milliseconds.

Thanks for reading πŸ™ŒπŸ‘‹

More articles