10

I am having lots of issues with tmux on Mac.

One problem I have is that I cannot bind a key in my tmux.conf to resize my panes.

What I need is the CTRL-b: resize-pane -U 10. I'm trying to increase the size of the pane upwards ten cells (or downwards or left or right) using a key shortcut instead of having to type this over and over (which I currently do unfortunately).

But I cannot find a way to configure this since on Mac, it seems that CTRL and other keys work differently on Linux.

Matthias Braun
  • 7,797
  • 7
  • 45
  • 54
Jim
  • 9,750
  • 15
  • 57
  • 84

3 Answers3

13

Below are my keybindings that let me resize a pane.

It uses Alt + direction, where the keys for the directions are the same as in Vim:

  k
h l
  j
# Resize the current pane using Alt + direction
bind -n M-k resize-pane -U 5
bind -n M-j resize-pane -D 5
bind -n M-h resize-pane -L 5
bind -n M-l resize-pane -R 5
Matthias Braun
  • 7,797
  • 7
  • 45
  • 54
8

In ~/.tmux.conf:

bind e resize-pane -U 10

Then, tmux source-file ~/.tmux.conf. (another useful shortcut: use the same principle).

Mateen Ulhaq
  • 681
  • 7
  • 13
Emanuel Berg
  • 6,763
  • 7
  • 43
  • 65
  • 2
    1) So `bind e resize-pane -U 10` is one line in `tmux` that binds the key `e` with the resize? Should I have pressed the `ctrl-b` before `e`? 2) I am not sure what you mean with `tmux source-file ~/.tmux.conf`. Doesn't `tmux` read the home directory's conf file? – Jim Jul 04 '13 at 19:43
  • @Jim: Yes, you hit the prefix key first. Then `e`. Yes, `tmux` does that, but it is faster to have it as a shortcut as well, so you don't have to restart `tmux` every time you make an improvement/extension in/to the init file. – Emanuel Berg Jul 04 '13 at 19:44
  • So `tmux source-file ~/.tmux.conf` is another line in `tmux.conf`? – Jim Jul 04 '13 at 19:46
  • @Jim: No, that would be something you type. In the init file, it could look like this: `bind u source-file ~/.tmux.conf` if you want this for `u`. – Emanuel Berg Jul 04 '13 at 19:50
  • @Jim: It works, and now that you know the principle, setup a bunch of shortcuts to do all sorts of stuff. Don't be too careful, just try stuff you think will work. – Emanuel Berg Jul 04 '13 at 19:53
  • BTW if you have spare time please check out this one in case you can figure this out http://unix.stackexchange.com/questions/81796/vim-and-tmux-are-conflicting-how-can-i-fix-this – Jim Jul 04 '13 at 20:09
  • 1
    why are you using `bind` and not `bind-key`? – Charlie Parker Jan 28 '16 at 22:04
4

There is already a shortcut: Hold down Ctrl, press b and then adjust the size with , etc. without releasing Ctrl.

Also, with

set -g mouse on

in ~/.tmux.conf you do it with the mouse. But with this setting active you need to hold Shift to do selections and paste with the scroll wheel.

  • 1
    doesnt work on mac unfortunately as ctrl+direction brings up mac window switcher – mirageglobe Feb 06 '21 at 11:31
  • 3
    Hey @JimmyMGLim , if you want you can disable ctrl+arrows shortcuts on MacOS: go to "Preferences -> Keyboard -> Shortcut -> Mission Control" and remove the checks on all four ctrl+arrow lines. I did it (I don't use those OS shortcuts anyway) and it works great. :) https://apple.stackexchange.com/questions/18043/how-can-i-make-ctrlright-left-arrow-stop-changing-desktops-in-lion – Bruno Belotti Mar 02 '21 at 15:22
  • Is there a way to make this faster? this approach takes forever to make big adjustments. – azizj Mar 16 '21 at 14:20
  • @azizj1 I updated the answer. – Jonatan Öström Mar 26 '21 at 19:41