September 25, 2014
Today I did a little bit of hacking around in tmux. Tmux is a tool that I use daily and I thoroughly enjoy what it provides to my development environment. Recently, @jarrodctaylor added a new feature to the dotfiles that myself and my team use to make resizing panes in Vim quicker. Using the dotfiles, in Vim, the arrow keys are used to resize panes. This works great when you need to resize panes by small intervals, however, if you want to quickly make a pane very large then small again it can be tedious. The change that Jarrod recently introduced was adding
<C-w><Up> (as well as Down, Left and Right) to resize the current pane by 50%. Awesome feature, I love it! Splits in Vim are great, and quick and easy ways of resizing them are even better.
I also use splits in Tmux very frequently. I wanted a similar shortcut to be able to quickly resize panes in Tmux quicker than one line or character at a time. I have found that keeping key mappings between Vim and Tmux extremely similar makes everything easier. For example: the dotfiles uses a Vim leader key of
<Space> and the Tmux leader key is
<C-Space>. To create a vertical split in Vim (using the aforementioned dotfiles) you can use
<Space> \ and a horizontal split using
<Space> -. In Tmux it is very similar except the leader is different. To create a vertical split in Tmux you can use
<C-Space> \ and a horizontal using
<C-Space> -. As you can see the only difference between the key mappings is the addition of the
<Control> key when you want to issue a command to Tmux instead of Vim.
I set out to create the same experience in Tmux with the 50% pane resize that we had in Vim. Unfortunately, I found that it was not possible. I was not able to map
<C-Space> w <Left> to a tmux command. I was however, able to get the functionality that I wanted even though I was not able to mirror the same key bindings that exist in Vim. I ended up adding the following to my
bind-key -n C-S-Up resize-pane -U 15 bind-key -n C-S-Down resize-pane -D 15 bind-key -n C-S-Left resize-pane -L 25 bind-key -n C-S-Right resize-pane -R 25
Now when I want to quickly resize a Tmux pane I can use
Control + Shift + Up/Down/Left/Right and it will closely mirror the killer feature that Jarrod recently added for our Vim setup.
I have never met a man so ignorant that I couldn't learn something from him. - Galileo Galilei