Resize Tmux and Vim Panes with Keyboard Shortcuts.
Resizing split panes in Tmux and Vim with the default key bindings is slow and fiddly. Here are the defaults, and the custom shortcuts I add to make it quick.
Vim
Vim defaults
Open the built-in help to see the window-resizing commands:
1:h window-resizing
The defaults are:
1CTRL-W = Make all windows (almost) equally high and wide
2CTRL-W - Decrease current window height by N (default 1)
3CTRL-W + Increase current window height by N (default 1)
4CTRL-W < Decrease current window width by N (default 1)
5CTRL-W > Increase current window width by N (default 1)
Bumping the step to 5
Moving one row/column at a time is slow — let’s bump it to 5. Add this to your .vimrc:
1noremap <C-w>+ :resize +5<CR>
2noremap <C-w>- :resize -5<CR>
3noremap <C-w>< :vertical resize -5<CR>
4noremap <C-w>> :vertical resize +5<CR>
Tmux
Tmux defaults
1usage: resize-pane [-DLRUZ] [-x width] [-y height] [-t target-pane] [adjustment]
So to resize a pane you type :resize-pane, then the direction (Down, Left, Right, Up) and the amount — too long to do repeatedly.
Creating a keymap
Add these lines to your .tmux.conf:
1bind -n C-Left resize-pane -L 2
2bind -n C-Right resize-pane -R 2
3bind -n C-Down resize-pane -D 1
4bind -n C-Up resize-pane -U 1
The -n flag means no prefix is needed: just hold Ctrl and tap the arrow keys to resize the pane until you’re happy, then release.