I'm discovering Tmux, and I'm facing an annoying problem:
When i switch window in Tmux with ctrl + arrow, Tmux keeps the focus on my keyboard.
here is an example of what it does: when i do ctrl + B [left arrow] [upper arrow], instead of going to the left window (terminal) and display my previous command, Tmux go to the left window, and then, to the upper window.
Anyone know any way to lose the focus after one command? I did not found any answers atm
Thanks
Add this to your ~/.tmux.conf
# command delay, don't want that, make it short
set -g escape-time 10
# Allow the arrow key to be used immediately after changing windows
set-option -g repeat-time 0
Related
How do I accomplish
[press C-a q] -> [me selecting one of the pane indices] -> [C-a z (to zoom)]
with just first two steps?
In other words, I want to rebind C-a q <NUMBER> so that the at the end, the selected pane is automatically zoomed in
I think this solution should work, put the following line in your .tmux.conf:
bind q choose-window "select-window -t '%%'; resize-pane -Z"
Then reload it by executing this command from the shell: tmux source ~/.tmux.conf
Note a couple things:
This has been tested on latest tmux version 1.9a. It might as well work on earlier versions (but I haven't tested).
Selecting a window is interactive! You can either press a <NUMBER> to select a window or use keyboard arrows to choose window.
Zooming feature will *toggle* zoom in the target window! So if the target window is already zoomed, it will get un-zoomed.
I am aware that I can manually bind individual keys in my .tmux.conf file, but according to this page I should be able to get vim-like key bindings in tmux simply by adding the following to my .tmux.conf, saving me having to maintain a list of keybindings:
set-window-option -g mode-keys vi
But this doesn't really seem to work as expected. Sure enough, when I press Ctrl+b [ I am able to navigate through my terminal history using vim keys hjkl, but when I press Ctrl+b k it doesn't take me to the above window, for that I still have to press Ctrl+b Up, same goes for down, left and right.
Why doesn't this work? Do I really have to map these keys manually on top of vi mode to get actual vi mode?
I'm using tmux 1.6
add this to your cnofig:
#switch panels
bind k selectp -U # switch to panel Up
bind j selectp -D # switch to panel Down
bind h selectp -L # switch to panel Left
bind l selectp -R # switch to panel Right
Is it possible to tell tmux to "resize a pane to 5 lines high"?
I know I can do resize-pane -U 3 to move the dividing line, but sometimes when logging in with a different size monitor the size has changed by a lot of lines that I can't judge by eye. I'd like to be able to have one command that will change one window to exactly the right number of lines rather than faffing about with multiple resize-pane commands.
What about Ctrl-B then (pressing Ctrl) + arrow?
If in tmux < 1.8, doing this by Ctrl-B then (Esc + arrow) * n, where n is the number of times you want to resize.
In tmux 1.8, the size of the panes may be adjusted interactively. Under the default key bindings this may be done by the prefix key (C-b) followed by the meta key combined with arrow keys (M-arrow), where arrow is one of the up/down/left/right arrow keys.
E.g. Ctrl-b followed by Alt-Up will adjust the size upwards.
Note that the Alt key may be held down while the up/down/left/right keys are pressed multiple times to make multiple adjustments.
E.g. Ctrl-b followed by Alt-Up-Up-Left will adjust the size upwards by two movements and left by one movement.
usage: resize-pane [-DLRUZ] [-x width] [-y height] [-t target-pane]
[adjustment]
ie.
resize-pane -t 1 -y 5
while pressing your bind key dont release your fingers and user the narrwors U D L R to resize your pan.
BindKey + R to resize to the right side.
On a Mac, it'd have to be <Prefix> + H/J/K/L on Tmux 1.8+. The arrow keys didn't work for me.
I've been a happy tmux user for a while now but there's one behaviour that's bugging me. When I switch panes using ^b-arrow, and then immediately press arrow-up (to get a command from history, for example), the window pane switches again. I understand this can be useful if you want to move through multiple panes quickly, but for me it's a pain in the backside since I keep ending up in panes I never meant to be in.
So, is there a way to set tmux so that the ^b-arrow command only switches pane once and ignores any following arrow key presses?
That happens because the default bindings for the arrow keys are setup with bind-key -r, specifying that they may be repeated. There are two ways that you can disable this.
First, you can use set-option repeat-time 0 to disable repeating entirely. This will affect all bindings. I find that to be very annoying when resizing panes.
Secondly, you can change the bindings for the arrow keys to use bind-key without the -r option:
bind-key Up select-pane -U
bind-key Down select-pane -D
bind-key Left select-pane -L
bind-key Right select-pane -R
If you spend a lot of times navigating panes, why not set up global mappings so you don't have to use prefixes at all, e.g. bind -n C-h select-pane -L to map ctrl-h to switching left, same as Vim.
See http://robots.thoughtbot.com/seamlessly-navigate-vim-and-tmux-splits for an even better solution that also navigates across Vim windows.
Another option is to make a binding to jump to the previous pane, if you are flicking back and forth between the same two panes.
bind-key C-a last-pane
I started a tmux session on a smaller terminal. When I "attach" to the same session on a larger resolution monitor, it draws dots around the console. It doesn't fit the new window size. Is there any way to redraw and clean the window? CTRL+L or CTRL-B + R doesn't help.
tmux limits the dimensions of a window to the smallest of each dimension across all the sessions to which the window is attached. If it did not do this there would be no sensible way to display the whole window area for all the attached clients.
The easiest thing to do is to detach any other clients from the sessions when you attach:
tmux attach -d
Alternately, you can move any other clients to a different session before attaching to the session:
takeover() {
# create a temporary session that displays the "how to go back" message
tmp='takeover temp session'
if ! tmux has-session -t "$tmp"; then
tmux new-session -d -s "$tmp"
tmux set-option -t "$tmp" set-remain-on-exit on
tmux new-window -kt "$tmp":0 \
'echo "Use Prefix + L (i.e. ^B L) to return to session."'
fi
# switch any clients attached to the target session to the temp session
session="$1"
for client in $(tmux list-clients -t "$session" | cut -f 1 -d :); do
tmux switch-client -c "$client" -t "$tmp"
done
# attach to the target session
tmux attach -t "$session"
}
takeover 'original session' # or the session number if you do not name sessions
The screen will shrink again if a smaller client switches to the session.
There is also a variation where you only "take over" the window (link the window into a new session, set aggressive-resize, and switch any other sessions that have that window active to some other window), but it is harder to script in the general case (and different to “exit” since you would want to unlink the window or kill the session instead of just detaching from the session).
You can always press CTRL-B + SHIFT-D to choose which client you want to detach from the session.
tmux will list all sessions with their current dimension. Then you simply detach from all the smaller sized sessions.
A simpler solution on recent versions of tmux (tested on 1.9) you can now do :
tmux detach -a
-a is for all other client on this session except the current one
You can alias it in your .[bash|zsh]rc
alias takeover="tmux detach -a"
Workflow: You can connect to your session normally, and if you are bothered by another session that forced down your tmux window size you can simply call takeover.
This is still the top post when searching, but it's no longer valid. Best answer is here, but the TLDR is
<c-b>:resize-window -A
You can use <Ctrl-B> : + at -d <CR> to redraw the tmux window.
The other answers did not help me as I only had client attached (the previous one that started the session was already detached).
To fix it I followed the answer here (I was not using xterm).
Which simply said:
Detach from tmux session
Run resize linux command
Reattach to tmux session
I just ran into this problem and stumbled across a different situation. Although it's probably just a unicorn, I thought I'd lay it out.
I had one session that was smaller, and I noticed that the font sizes were different: the smaller session had the smaller fonts. Apparently, I had changed window font sizes for some reason.
So in OS X, I just did Cmd-+ on the smaller sized session, and it snapped back into place.
Probably an strange edge case but for me the only thing that fixed it was unmaximizing the window and then maximizing it again.
ps ax | grep tmux
17685 pts/22 S+ 0:00 tmux a -t 13g2
17920 pts/11 S+ 0:00 tmux a -t 13g2
18065 pts/19 S+ 0:00 grep tmux
kill the other one.
I had the same problem because of using iTerm's tmux integration (i.e., tmux -CC a).
None of the detach options mentioned in the other answers worked for me, because there was no "other sessions" to detach from.
My understanding is iTerm's tmux client seems to hard set the window size on the attached session, so the subsequent attaches seem to respect the previously resized window size.
Alas, I ended up reattaching iTerm client to tmux via tmux -CC a and manually resized to full window size in GUI (not happy using mouse here, but that is what worked in the end, unfortunately). Clean detach from iTerm and subsequent attaches follows the size set in iTerm.
I use Ctrl-b + q which makes it flash number for each pane, redrawing them on the way.