Điều chỉnh kích thước khung chia màn hình trong tmux


50

I'd like to resize the panes so I can expand / compress the pane sizes (up / down / left / right etc) ..

Any way to get this done?

Câu trả lời:


64

Assuming your prefix key is still the default of Ctrl-B
^B :resize-p -D 2
^B :resize-p -U 2
^B :resize-p -L 2
^B :resize-p -R 2
The numbers at the end are optional, defaulting to 1. The -U is also a default, and is unnecessary.

If you ever forget that, ^B ? will show these found to C-Up and C-Down and C-Left and C-Right, at the end of the keys (with the default key bindings).

You could also try pressing Ctrl+B followed by a Ctrl+arrow-keys.
However, note that Ctrl-arrow-keys may be problematic on some terminals. So you can either try to address the terminal limitations, or create new shortcut key bindings, or just not use shortcuts and use the longer commands shown above.


37
On my macbook, by default I can use Ctrl+B, then Esc + (arrow key).
James M. Lay

2
@JamesM.Lay Oh ya it works either, but how if I want to add 2 or more size? because esc + (arrow) only work once, after that I have to using Ctrl+B then re-apply esc + (arrow) again.
Adiyat Mubarak

4
@AdiyatMubarak You won't have to use Ctrl+B again if you press Esc + (arrow) in quick succession. Agreed this is not very comfortable, but it works.
th3an0maly

2
@JamesM.Lay alternatively Ctrl+B and M-(arrow) works for me. Usually alt and Esc both send Meta
oLas

Ctrl+B and then keep option pressed while hitting an arrow key however many times are needed works for me.
Yuxuan Chen

39

One option for resizing panes is to use the mouse. To do this, add these lines to your .tmux.conf:

set -g mode-mouse on
set -g mouse-resize-pane on

If you are on a Mac and the above doesn't work, use this instead (source):

set-option -g mouse on

Once this mode is on, simply click and drag on pane dividers to resize them.


3
set -g mouse on #for newer versions
Loves Probability

My life just changed! This works on my Ubuntu instance on WSL (Windows Subsystem for Linux) ... oh, but now I can't paste with the right mouse button anymore. Linux on Window is still awkward.
flickerfly

21

I just added the following lines to my tmux.conf file

bind j resize-pane -D 10
bind k resize-pane -U 10
bind l resize-pane -L 10
bind h resize-pane -R 10

and now I can use Ctrl-a (my prefix key) with [h|j|k|l] to resize the panes


1
And now I cannot use h|j|k|l keys
subhojit777

1
@subhojit777 .. You should still be able to use the [h|j|k|l] keys. Remember for resizing tmux panes you still have to add the prefix key (Ctrl-b by default .. Ctral-a was my override) before you hit those keys. Also, you always have the option to change the binding to whatever you want .. the point was to let people know about saving it in the tmux.conf file
Prashant

You should swap l with h to have the VI bindings.
Hendrik

8

Assuming your prefix key is Ctrl-B (Cmd-B on Mac):

  1. Press Ctrl-B and release
  2. Press and hold Meta (Option on Mac)
  3. While holding Meta press arrow keys repeatedly to resize current pane

It seems however that there is some timeout so if you don't press an arrow key while holding Meta within 1 or 2 seconds Meta-{arrow} will be considered as an input in current prompt.


6

I just discovered another way. Apparently tmux has two different kinds of key presses (assuming that your prefix key is still Ctrlb)

  1. Press Ctrlb, lift your fingers then press one of the arrow keys. This switches focus.
  2. Press Ctrlb, don't lift your fingers, and then press one of the arrow keys simultaneously. This resizes panes, and I guess is faster than any of the other methods.

In a similar fashion, Ctrlbo also has different behaviours. The first kind of keypress switches focus, and the second kind of keypress swaps panes.


Nice job finding the "works out of the box" example.
Cloud
Khi sử dụng trang web của chúng tôi, bạn xác nhận rằng bạn đã đọc và hiểu Chính sách cookieChính sách bảo mật của chúng tôi.
Licensed under cc by-sa 3.0 with attribution required.